Date: Mon, 17 Dec 2001 07:04:57 +0100 From: "Michal F. Hanula" <frankie@kyblik.pieskovisko.sk> To: freebsd-questions@freebsd.org Subject: Re: ping failure script Message-ID: <20011217070457.A273@kyblik.pieskovisko.sk> In-Reply-To: <113fc9110004.110004113fc9@mbox.com.au>; from bsd-freak@mbox.com.au on Mon, Dec 17, 2001 at 02:03:48PM %2B1100 References: <113fc9110004.110004113fc9@mbox.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
--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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011217070457.A273>