From owner-freebsd-questions Sun Dec 16 20:19:40 2001 Delivered-To: freebsd-questions@freebsd.org Received: from falcon.prod.itd.earthlink.net (falcon.mail.pas.earthlink.net [207.217.120.74]) by hub.freebsd.org (Postfix) with ESMTP id 9CFA037B416 for ; Sun, 16 Dec 2001 20:19:36 -0800 (PST) Received: from dialup-209.244.105.100.dial1.sanjose1.level3.net ([209.244.105.100] helo=blossom.cjclark.org) by falcon.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16FpFX-0003MC-00; Sun, 16 Dec 2001 20:19:35 -0800 Received: (from cjc@localhost) by blossom.cjclark.org (8.11.6/8.11.3) id fBH4JVl16105; Sun, 16 Dec 2001 20:19:31 -0800 (PST) (envelope-from cjc) Date: Sun, 16 Dec 2001 20:19:31 -0800 From: "Crist J . Clark" To: Ryan Thompson Cc: BSD Freak , FreeBSD Questions Subject: Re: ping failure script Message-ID: <20011216201931.E15624@blossom.cjclark.org> References: <113fc9110004.110004113fc9@mbox.com.au> <20011216211234.Y12124-100000@catalyst.sasknow.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20011216211234.Y12124-100000@catalyst.sasknow.net>; from ryan@sasknow.com on Sun, Dec 16, 2001 at 09:31:53PM -0600 X-URL: http://people.freebsd.org/~cjc/ 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 Sun, Dec 16, 2001 at 09:31:53PM -0600, Ryan Thompson wrote: > BSD Freak wrote to FreeBSD Questions: > > > 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 > > How about this? > > #!/bin/sh > > PING="/sbin/ping -q -c 3" > > if $PING $1 >/dev/null 2>&1; then > echo "$1 is up" > else > echo "$1 is down" > fi > > > ping will only fail if no replies are received. > The above example could use some better input error handling, > but otherwise, it should do what you want. Nope, ping(1) will never die if it doesn't get the responses. You need to add the '-w' option. Something like, PING="/sbin/ping -q -c 3 -w 10" Should do it. -- "It's always funny until someone gets hurt. Then it's hilarious." Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message