#!/bin/bash
#
# pinghost - Danny Sauer, (last updated Mar 9, 1999)
# call as "pinghost host.do.main"
# if the host doesn't respond, send an e-mail to the administrator
# written for someone on the LUCI mailing list - I forget who
hosttoping=$1
adminaddress="root@localhost"
failmessage="$hosttoping is not responding."
failedpingtext='100% packet loss'
myname=${0##/*/}
# call me with one argument - the host to ping
if [ -z "$1" ]; then
echo "usage: $myname hostname"
exit 1
fi
# ping once, quietly, get the last line, and grab the third chunk
hoststatus=$(ping $hosttoping -c1 -q|tail -n1|cut -d, -f3)
# get rid of the leading space
hoststatus=${hoststatus#\ }
# check for failure
if [ "$hoststatus" = "$failedpingtext" ]; then
echo $failmessage | mail -s "$hosttoping failure" $adminaddress
fi |