#! /bin/sh # pingmon - monitor host up/down status using 'ping' # # usage: pingmon hostaddress description mailaddress... # # also: entry in crontab file like - # 3,13,23,33,43,53 * * * * pingmon 1.2.3.4 "VIP host" user1 user2@host2 # # Rex Sanders, USGS, February 1992 # mod 7/95 RS - add description field host=$1 shift desc=$1 shift users=$@ /usr/etc/ping -s $host 56 5 2> /dev/null | \ if grep '100% packet loss$' > /dev/null then # host is down, check to see if it has been down a while if [ -f /tmp/pingmon.$host ] then # host was down, do nothing true exit 2 else # host just went down, send message and create log day=`date '+19%y/%m/%d'` time=`date '+%T'` ( echo "$desc - $host down at $day $time" echo "So sorry, pingmon@"`hostname` ) | \ /usr/ucb/mail -s "$desc DOWN at $time" $users echo "$desc - $host down at $day $time" > /tmp/pingmon.$host exit 1 fi else # host is up, check to see if it was down if [ -f /tmp/pingmon.$host ] then # host was down, send message and clean up day=`date '+19%y/%m/%d'` time=`date '+%T'` echo >> /tmp/pingmon.$host echo "$desc - $host UP at $day $time" >> /tmp/pingmon.$host echo >> /tmp/pingmon.$host echo "Yippy!, pingmon@"`hostname` >> /tmp/pingmon.$host /usr/ucb/mail -s "$desc UP at $time" $users < /tmp/pingmon.$host rm /tmp/pingmon.$host fi fi