*********UNIX/LINUX******** Ping wrapper . Call the script: myping Develop basic
ID: 3771957 • Letter: #
Question
*********UNIX/LINUX********
Ping wrapper. Call the script: myping
Develop basic script
# implement the following syntax:
myping -p npack -h host1 [ host2 host3 ... ]
(the [] brackets indicate optional parameters).
# a "Usage" message stored in a variable (this is usually the command syntax).
# at least one function, including an error function that will print out whatever text is supplied to it as arguments and exit with a non-zero exit status.
# the use of an "if" statement to check for correct number of arguments. If the number is incorrect, it calls the error function to display the Usage message and exit.
# argument handling: At least four arguments are required.
* the first argument should be "-p" followed by the number of packets to send
* the third argument should "-h" followed by at least one hostname. There can be any number of hostnames separated by spaces (this makes "getopts" unusable for this part).
# the use of a "for" or a "while" loop. For each host make just one call to ping.
# a way to filter the ping results for each host to display JUST the Statistics or Error Messages.
# remove any temporary files at the end.
Explanation / Answer
#!/bin/bash
# A shell script to start / stop / restart nfsv4 services
_me=${0##*/} #Who am I? Server or client?
_server="/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock /etc/init.d/nfs" # list of server init scripts
_client="/etc/init.d/rpcbind /etc/init.d/rpcidmapd /etc/init.d/nfslock" # list of client init scripts
_action="$1" # start / stop / restart
# run all scripts with one action such as stop or start or restart
runme(){
local i="$1"
local a="$2"
for t in $i
do
$t $a
done
}
usage(){
echo "$_me start|stop|restart|reload|status";
exit 0
}
[ $# -eq 0 ] && usage
# main logic - take action
case $_me in
nfs.server) runme "$_server" "$_action" ;;
nfs.client) runme "$_client" "$_action" ;;
*) usage
esac
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.