Date: Tue, 18 Dec 2001 13:16:06 -0500 From: devin-freebsdquestions@rintrah.org To: Garance A Drosihn <drosih@rpi.edu> Cc: freebsd-questions@freebsd.org Subject: Re: ping failure script Message-ID: <20011218131606.A81236@tharmas.rintrah.org> In-Reply-To: <p05101004b84536ec64a9@[128.113.24.47]>; from drosih@rpi.edu on Tue, Dec 18, 2001 at 01:10:43PM -0500 References: <113fc9110004.110004113fc9@mbox.com.au> <p05101004b84536ec64a9@[128.113.24.47]>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 18, 2001 at 01:10:43PM -0500, Garance A Drosihn wrote: > At 2:03 PM +1100 12/17/01, BSD Freak wrote: > >I want to run a shell script from cron that has the following > >logic but I am totally unsure where to start with the syntax. > >It goes like this: > > > >IF 3 consecutive pings to my.host.com fail THEN > >echo "Link is DOWN!!" | mail me@mycompany.com > >end > > Check the 'fping' module in ports. It is designed to make this > sort of checking much easier (particularly if you are checking > multiple hosts). > fping even provides a sample perl script to do exactly that sort of checking in the man page. #!/usr/bin/perl require 'open2.pl'; $MAILTO = "root"; $pid = &open2("OUTPUT","INPUT","/usr/local/sbin/fping -u"); @check=("slapshot","foo","foobar"); foreach(@check) { print INPUT "$_\n"; } close(INPUT); @output=<OUTPUT>; if ($#output != -1) { chop($date=`date`); open(MAIL,"|mail -s 'unreachable systems' $MAILTO"); print MAIL "\nThe following systems are unreachable as of: $date\n\n"; print MAIL @output; close MAIL; } --devin To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011218131606.A81236>