From owner-freebsd-questions Tue Dec 18 10:16:13 2001 Delivered-To: freebsd-questions@freebsd.org Received: from tharmas.rintrah.org (dhcp065-031-016-002.insight.rr.com [65.31.16.2]) by hub.freebsd.org (Postfix) with SMTP id 4D86E37B416 for ; Tue, 18 Dec 2001 10:16:07 -0800 (PST) Received: (qmail 81336 invoked by uid 1000); 18 Dec 2001 18:16:06 -0000 Date: Tue, 18 Dec 2001 13:16:06 -0500 From: devin-freebsdquestions@rintrah.org To: Garance A Drosihn Cc: freebsd-questions@freebsd.org Subject: Re: ping failure script Message-ID: <20011218131606.A81236@tharmas.rintrah.org> Mail-Followup-To: Garance A Drosihn , freebsd-questions@freebsd.org References: <113fc9110004.110004113fc9@mbox.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from drosih@rpi.edu on Tue, Dec 18, 2001 at 01:10:43PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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=; 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