From owner-freebsd-questions Sun Dec 16 19:30: 5 2001 Delivered-To: freebsd-questions@freebsd.org Received: from catalyst.sasknow.net (catalyst.sasknow.net [207.195.92.130]) by hub.freebsd.org (Postfix) with ESMTP id BD18537B41B for ; Sun, 16 Dec 2001 19:29:59 -0800 (PST) Received: from localhost (ryan@localhost) by catalyst.sasknow.net (8.11.6/8.11.6) with ESMTP id fBH3Vr912680; Sun, 16 Dec 2001 21:31:54 -0600 (CST) (envelope-from ryan@sasknow.com) X-Authentication-Warning: catalyst.sasknow.net: ryan owned process doing -bs Date: Sun, 16 Dec 2001 21:31:53 -0600 (CST) From: Ryan Thompson X-X-Sender: To: BSD Freak Cc: FreeBSD Questions Subject: Re: ping failure script In-Reply-To: <113fc9110004.110004113fc9@mbox.com.au> Message-ID: <20011216211234.Y12124-100000@catalyst.sasknow.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 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. Hope this helps. - Ryan -- Ryan Thompson Network Administrator, Accounts SaskNow Technologies - http://www.sasknow.com #106-380 3120 8th St E - Saskatoon, SK - S7H 0W2 Tel: 306-664-3600 Fax: 306-664-1161 Saskatoon Toll-Free: 877-727-5669 (877-SASKNOW) North America To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message