Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!howland.reston.ans.net!swrinde!elroy.jpl.nasa.gov!ames!tulane.edu!cpk-news-feed4.bbnplanet.com!news.fsu.edu!gold!davis
From: davis@gold (Douglass E. Davis)
Newsgroups: comp.sys.sun.admin,alt.sys.sun,comp.unix.bsd.misc,comp.unix.programmer,comp.unix.bsd.bsdi.misc,comp.unix.admin
Subject: Re: ping script
Date: 23 Jul 1996 15:09:17 GMT
Organization: Florida State University
Lines: 96
Distribution: world
Message-ID: <4t2put$n1i@news.fsu.edu>
References: <Pine.SOL.3.93.960702171209.4062B-100000@gold.acns.fsu.edu> <4sbfat$ll@keyhole.west.spy.net>
NNTP-Posting-Host: gold.acns.fsu.edu
X-Newsreader: TIN [version 1.2 PL2]
Xref: euryale.cc.adfa.oz.au comp.sys.sun.admin:71048 alt.sys.sun:10438 comp.unix.bsd.misc:1261 comp.unix.programmer:39973 comp.unix.bsd.bsdi.misc:4366 comp.unix.admin:45222
The new ping script will not stall when one host is down, but it
will just mark the host as down, send mail, and keep going with the other
ipnumbers, when it comes back up it will send mail again. Thanks for the
help every one.
Here is the new and improved ping script if anybody wants it:
#!/bin/sh
#written by Douglass Davis and others
# names of important people to mail, separated by spaces.
MAIL_TO="ddavis@cis.famu.edu yourname@youraddress.com"
if [ ! -d host_down ]; then
echo $0: a directory called host_down
echo $0: must be in the sonar directory.
exit 1
fi
rm -f host_down/down*
echo `date`: $0 started >> sonar.log
echo --------------------------->> sonar.log
echo >> sonar.log
while [ /usr/bin/true ]
do
for ip in `cat ipnums`
do
# first get the description of the current
# ip address from the ipdesc file
desc=`grep -w $ip ipdesc`
if [ $? != 0 ]
then
desc=`echo $ip: no description available`
fi
desc=`echo \"$desc\"`
# do 3 pings. Even if there is a good connection,
# there is a chance a ping or two may not respond.
ping $ip > /dev/null 2>&1
rc1=$?
ping $ip > /dev/null 2>&1
rc2=$?
ping $ip > /dev/null 2>&1
rc3=$?
# do this part if no pings came back, and there is no file
# in the ipnums directory indicating host was down already
if [ $rc1 != 0 ] && [ $rc2 != 0 ] && [ $rc3 != 0 ] &&
[ ! -f host_down/down-$ip ]
then
# make a file in the host_down directory for this ip address
touch host_down/down-$ip
# mail important people
echo "`date` PING TO $desc FROM `hostname` DID NOT RETURN" | fmt | mail -s "`hostname` communications error" $MAIL_TO
# do a display to the screen
echo sonar: ping to $desc did not return
echo
# add to log
echo `date`: PING TO $desc DID NOT RETURN | fmt >> sonar.log
echo >> sonar.log
elif ( [ $rc1 = 0 ] || [ $rc2 = 0 ] || [ $rc3 = 0 ] ) &&
[ -f host_down/down-$ip ]
then
rm host_down/down-$ip
# mail important people
echo "`date` PING TO $desc from `hostname` RETURNED communications recovered" | fmt | mail -s "`hostname` communications recovery" $MAIL_TO
# do a display to the screen
echo sonar: ping to $desc returned, communications recovered
# add to log
echo `date`: echo PING TO $desc RETURNED | fmt >> sonar.log
echo >> sonar.log
fi
done
#wait 5 Minutes, and do checks again
sleep 300
done