Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.netspace.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.Hawaii.Edu!news.uoregon.edu!newsfeed.orst.edu!richie.supra.com!uunet!in2.uu.net!news.iij.ad.jp!news.dnsa.or.jp!usenet From: Ricky Roque <ricky@dynanet.ad.jp> Newsgroups: comp.unix.bsd.bsdi.misc Subject: Re: ping script Date: Fri, 25 Oct 1996 16:34:52 +0900 Organization: Dynanet Services Asia Lines: 110 Message-ID: <32706D9C.2B94@dynanet.ad.jp> References: <32675AB1.2CCD@netdirect.net> Reply-To: ricky@dynanet.ad.jp NNTP-Posting-Host: dhcp045.dynanet.ad.jp Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0Gold (Win95; I) To: mrw@netdirect.net Mark Wilson wrote: > > I saw some traffic a while back about a ping script. Did anyone ever > come up with one that worked? > > Mark Wilson > mrw@netdirect.net I use this one I took from this discussion group(I think), and it works. --------------------------- #!/bin/sh #written by Douglass Davis and others # names of important people to mail, separated by spaces. MAIL_TO="ricky@dnsa.or.jp" if [ ! -d /home/ricky/sonar/host_down ]; then echo $0: a directory called host_down echo $0: must be in the sonar directory. exit 1 fi rm -f /home/ricky/sonar/host_down/down* echo `date`: $0 started >> /home/ricky/sonar/sonar.log echo --------------------------->> /home/ricky/sonar/sonar.log echo >> /home/ricky/sonar/sonar.log #while [ /usr/bin/true ] #do for ip in `cat /home/ricky/sonar/ipnums` do # first get the description of the current # ip address from the ipdesc file desc=`grep -w $ip /home/ricky/sonar/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. /usr/etc/ping $ip > /dev/null 2>&1 rc1=$? /usr/etc/ping $ip > /dev/null 2>&1 rc2=$? /usr/etc/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 echo $rc1 if [ $rc1 != 0 ] && [ $rc2 != 0 ] && [ $rc3 != 0 ] && [ ! -f /home/ricky/sonar/host_down/down-$ip ] then # make a file in the host_down directory for this ip address touch /home/ricky/sonar/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 >> /home/ricky/sonar/sonar.log echo >> /home/ricky/sonar/sonar.log elif ( [ $rc1 = 0 ] || [ $rc2 = 0 ] || [ $rc3 = 0 ] ) && [ -f /home/ricky/sonar/host_down/down-$ip ] then rm /home/ricky/sonar/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 >> home/ricky/sonar/sonar.log echo >> /home/ricky/sonar/sonar.log fi done #wait 5 Minutes, and do checks again # sleep 300 #done ------------------- Hope it helps. -- ricardo roque ikebukuro,tokyo dynanet services asia japan ricky@dynanet.ad.jp