#!/bin/csh -f #
######################### DO NOT REMOVE THIS HEADER ################################# # # # Birds-Eye Network Services, LLC # # Birds-Eye.Net's Generic PING script # # ping.csh # # # # Run this script periodically (every 5 or so minutes) to check for network # # connectivity between local host and remote host. # # # # By: Bruce Bahlmann # # (C) Copyright, Birds-Eye Network Services, LLC, ALL RIGHTS RESERVED # # # # NOTICE: All use of the software (in whole or in part) is restricted. Any sale, # # marketing, distribution, or transfer of software copies, associated data, source # # code, information (including manuals), configuration files, or licenses are # # restricted. Internal use of this software requires a license and/or express # # written permission from Birds-Eye Network Services, LLC. Any other use of this # # software is restricted. This software is not sold as part of an enterprise # # license and thus is restricted as such. # # # # To purchase access rights to this software contact: # # Birds-Eye.Net, LLC # # info[_at_]birds-eye.net # # OR go to www.birds-eye.net/consulting to obtain a license # # # ######################### DO NOT REMOVE THIS HEADER ################################# # Generic PING script # Created: 03/24/2000 # Version: 01.00 03/24/2000 bbahlmann Initial release # USAGE: ping.csh# Run this script periodically (every 5 or so minutes) to check for network # connectivity between local host and remote host. Script will ping the # remote host and if NOT successful, it will save this DOWN state in $dfile # which is particular to the IP being pinged. If, on the next subsequent # ping, the down state is NOT restored an email will be sent to the email # address provided. If the down state is restored, the DOWN state will be # cleared and the script will reset as if the network connection was ever # dropped. Note that only ONE email will be sent. # # TODO: May want to record repeated ping failures as this may be the sign of # a potential network problem. Note in order to troubleshoot repeated ping # failures one should record the date/time of each failure. # if ($#argv > 0) then set dfile = "/tmp/$argv[1]" set sent = "/tmp/sent$argv[1]" set to = "5" # timeout for ping operation set ping = "/usr/sbin/ping" ## use tail to only capture last line of output set cmd = "$ping $argv[1] $to" set rsp = `$cmd | tail -1` if ("$rsp" !~ *alive) then ## Host is detected as being DOWN set date = `date` if (-e $sent) then echo "alert already sent" else if ((-e $dfile) && ! -e $sent) then ## alert echo "send alert" mailx -s "Possible Outage" $argv[2] < $dfile echo "$date" > $sent else echo "ping failed -- saving state" echo "unable to reach [$argv[1]] on $date" > $dfile endif else ## Host is detected as being ALIVE if (-e $dfile) then echo "Clearing previous ALARM state" rm $dfile if (-e $sent) then rm $sent endif else echo "$rsp" endif endif else echo "USAGE: $0 " endif