From owner-freebsd-questions Sun Dec 16 22: 5: 5 2001 Delivered-To: freebsd-questions@freebsd.org Received: from kyblik.pieskovisko.sk (kyblik.pieskovisko.sk [195.168.39.59]) by hub.freebsd.org (Postfix) with SMTP id 421FE37B405 for ; Sun, 16 Dec 2001 22:05:02 -0800 (PST) Received: (qmail 401 invoked by uid 19508); 17 Dec 2001 06:04:57 -0000 Date: Mon, 17 Dec 2001 07:04:57 +0100 From: "Michal F. Hanula" To: freebsd-questions@freebsd.org Subject: Re: ping failure script Message-ID: <20011217070457.A273@kyblik.pieskovisko.sk> References: <113fc9110004.110004113fc9@mbox.com.au> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="5mCyUwZo2JvN/JJP" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <113fc9110004.110004113fc9@mbox.com.au>; from bsd-freak@mbox.com.au on Mon, Dec 17, 2001 at 02:03:48PM +1100 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 --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 17, 2001 at 02:03:48PM +1100, BSD Freak wrote: > Hi all, >=20 > I want to run a shell script from cron that has the following logic=20 > but I am totally unsure where to start with the syntax. It goes like=20 > this: >=20 > IF 3 consecutive pings to my.host.com fail THEN > echo "Link is DOWN!!" | mail me@mycompany.com > end >=20 >=20 > Thanks in advance.... #get the summary line (a packets transmitted, b packets received, c% # packet loss) PING_SUMMARY=3D$(ping -c ${COUNT} -t ${TIMEOUT} -q ${IP} 2>&1 | tail -1 | = head -1) # get the ``b'' from the line COUNT=3D$(expr "${PING_SUMMARY}":'.* \([0-9]*\) packets received') #If it is 0, do what is needed. if [ ${COUNT} -eq 0 ]; then echo "Link is DOWN!!!" | mail me@mycompany.com fi No time to test it, use at your own risk. HTH. (m&f) --5mCyUwZo2JvN/JJP Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) Comment: For info see http://www.gnupg.org iD8DBQE8HYsJuOi7geABv0QRAi37AJ4/xRTr953bvyuI/1eZQ8jPSsJ5fwCbBVOw 8z4T0Grc/oi22+KNF3Lna5Y= =YWwZ -----END PGP SIGNATURE----- --5mCyUwZo2JvN/JJP-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message