This was one of those tasks that was quicker to write my own than it was to Google up one of the several hundred other identical monitoring scripts.
This script monitors whether or not a host is responding to ICMP and can be happily set to a resolution of 1 second. It’s written in bash and will happily run on my linux. It should run on yours, too.
./pingit 1 myHostname.dyndns.org > /var/log/myIspIsNotIdeal.log
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: $0 <timeout in seconds> <hostname to ping>"
exit 1
fi
while true
do
echo -n "$(date) "
ping -q -c 1 -W $1 $2 > /dev/null
case $? in
1)
echo "down"
;;
0)
echo "ok"
sleep $1
;;
2)
echo "the damage report machine has exploded"
;;
esac
done
Run it and redirect its output to a file for later grepping. Once I’m happy its bedded in and working, and I’ve finished tarting it about a bit, I’ll make it only output a line on failure.
#1 by Dav on June 16th, 2009 - 2:26 pm
bah, that code was indented before I posted it..