From owner-freebsd-questions Mon Dec 17 1:14:37 2001 Delivered-To: freebsd-questions@freebsd.org Received: from post.mail.nl.demon.net (post-10.mail.nl.demon.net [194.159.73.20]) by hub.freebsd.org (Postfix) with ESMTP id 5CBAC37B416 for ; Mon, 17 Dec 2001 01:14:33 -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 16Ftqw-00036c-00 for freebsd-questions@FreeBSD.ORG; Mon, 17 Dec 2001 09:14:30 +0000 Received: by tanya.raggedclown.net (tanya.raggedclown.net, from userid 500) id 37C741147; Mon, 17 Dec 2001 10:14:29 +0100 (CET) Date: Mon, 17 Dec 2001 10:14:29 +0100 From: Cliff Sarginson To: FreeBSD Questions Subject: Re: ping failure script Message-ID: <20011217091429.GA1352@raggedclown.net> References: <113fc9110004.110004113fc9@mbox.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <113fc9110004.110004113fc9@mbox.com.au> 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 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message