(Answer) (Category) Products of Aardvarks With Chisels : (Category) Linux : (Category) Handy shell scripts :
pinghost
#!/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
[Append to This Answer]
2000-Jul-12 1:02am
Previous: (Answer) pppcheck
Next: (Answer) printimages.pl
This document is: http://www.cloudmaster.com/~sauer/projects/index.cgi?file=84
[Search] [Appearance]
This is a Faq-O-Matic 2.719.
This FAQ administered by sauer@cloudmaster.com