From owner-freebsd-questions Mon Dec 17 1:21:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from post.mail.nl.demon.net (post-11.mail.nl.demon.net [194.159.73.21]) by hub.freebsd.org (Postfix) with ESMTP id D13FE37B41B for ; Mon, 17 Dec 2001 01:21:22 -0800 (PST) Received: from [212.238.194.207] (helo=tanya.raggedclown.net) by post.mail.nl.demon.net with esmtp (Exim 3.33 #1) id 16FtxZ-0004Bb-00 for freebsd-questions@FreeBSD.ORG; Mon, 17 Dec 2001 09:21:21 +0000 Received: by tanya.raggedclown.net (tanya.raggedclown.net, from userid 500) id E5D2A1147; Mon, 17 Dec 2001 10:21:19 +0100 (CET) Date: Mon, 17 Dec 2001 10:21:19 +0100 From: Cliff Sarginson To: FreeBSD Questions Subject: Re: ping failure script Message-ID: <20011217092119.GA1904@raggedclown.net> References: <113fc9110004.110004113fc9@mbox.com.au> <20011217091429.GA1352@raggedclown.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20011217091429.GA1352@raggedclown.net> User-Agent: Mutt/1.3.24i 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 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