# UNIX ping script. written Warren Kibbe, 1996 # WAKibbe@nwu.edu # # version 1.0 release 2 # Changes 9/26/96. # - Script is no longer path dependent. # - run under the "sh" shell # - pass to it the subnet to be 'ping'ed in the command line # : sh ping.sh 129.1.1 # - may need exact path for crontab entry # : 54 08 * * 5 sh /user/myhome/ping.sh 129.105.72 # runs at 08:54 every friday # # ******** Variables ******** mailbox="wak@nwu.edu" #destination for notifications scriptname="ping.sh" #name of the script file permlogfile="oldbslog" #this is where the permanent log is kept logfilename="bslog" #this is where the daily log file is kept baselog="ping" path="/home/u1/kibbe/" # makes the script run from directories # other than root (login) newlogfile="$baselog" logpath="/home/u1/kibbe/ping/raw/" # directory for ping results # ******** Main Body of Script ******** now=`date` # to debug this script, comment out the next line exec > /dev/null 2>&1 #this routes all messages into 'nothing' cd $path # messages from "grablog" and "statbot" are routed to null (trash) # replace with pipe to email if you want the output #/users/pib/bin/grablog > "$logpath$newlogfile" 2> /dev/null #/users/pib/statbot/statbot > /dev/null 2>&1 cd $logpath echo "starting command loop: $#, first arg = $1" temp="" while [ $# -gt 0 ] do case "$1" in *) subnet="$1" logfile="$baselog$subnet" counter=1 if [ -r "$logpath$logfile" ] then echo "Made it inside logfile test" rm -f "$logpath$logfile" fi echo "ping started at $now" >> "$logpath$logfile" while [ $counter -lt 255 ] do ip="$subnet.$counter" result=`/usr/local/bin/perl /home/u1/kibbe/iplookup.pl "$ip"` echo "iplookup result = $result" pingresult=`/usr/etc/ping -s $ip 50 2` echo "ping result = $pingresult" isthere=`/usr/local/bin/perl /home/u1/kibbe/ping.pl "$pingresult"` echo "ping.pl result = $isthere" if [ "X$result" = "X " ] then echo "$ip = **unregistered**" >> "$logpath$logfile" else echo "$ip = $result" >> "$logpath$logfile" fi if [ "X$isthere" = "X1" ] then /usr/etc/ping -s $ip 512 5 >> "$logpath$logfile" else echo "$pingresult" >> "$logpath$logfile" fi counter=`expr $counter + 1` done temp=$temp"Finishing with subnet $subnet \n";; esac shift done echo "leaving command line parsing" #comment this out to sop email notifications every time script runs echo $temp | mail $mailbox # Final action: