Date: Mon, 17 Dec 2001 10:21:19 +0100 From: Cliff Sarginson <cliff@raggedclown.net> To: FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: ping failure script Message-ID: <20011217092119.GA1904@raggedclown.net> In-Reply-To: <20011217091429.GA1352@raggedclown.net> References: <113fc9110004.110004113fc9@mbox.com.au> <20011217091429.GA1352@raggedclown.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Dec 17, 2001 at 10:14:29AM +0100, Cliff Sarginson wrote:
> On Mon, Dec 17, 2001 at 02:03:48PM +1100, BSD Freak wrote:
> > Hi all,
> >
> > 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
>
> ping -q -c 3 -w 1 my.host.com >/dev/null
> [ $? -ne 0 ] && { echo "Link is DOWN!!" | mail me@mycompany.com"; }
>
> Only problem with this is that you will get the message consequent on the
> effect of the last ping.
>
> Perhaps you could better try it this way:
>
> FAIL=0
> for LOOP in 1 2 3
> do
> ping -q -c 1 -w 1 my.host.com >/dev/null
> [ $? -eq 0 ] && { break; }
> FAIL=$LOOP
> done
>
> case $LOOP in
> 0) :
> ;;
> 1|2) echo "Link is flaky" | mail me@mycompany.com;
> ;;
> 3) echo "Link is down" | mail me@mycompany.com;
> ;;
> *) ;;
> esac
>
> So if ping number 1 succeeds all is assumed ok.
> If ping 1 or 2 fail but ping 3 succeeds, there may be a problem
> If all 3 pings fail assume your link is down.
>
> But this is also not exactly what you asked for, may give you
> a hint though.
>
> --
> Regards
> Cliff
Mmm, the -w parameter is defunct, another post tells you about that.
Same logic could be used though.
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?20011217092119.GA1904>
