#!/bin/sh IP="66.230.156.1" ADDRESS="email@address.com" DEBUG=1 state="up" while true do if [ "$DEBUG" != "" ]; then echo "o `date` : Testing $IP" fi RES=`fping $IP` GRP=`echo $RES | grep alive | wc -l` if [ $GRP -lt 1 ]; then # must be down if [ "$state" = "down" ]; then #must have been down before notify=0; else notify=1; state="down" fi if [ "$DEBUG" != "" ]; then echo "o `date` : Test results : Target is $state" fi else if [ "$state" = "up" ]; then #must have been up before notify=0; else state="up" notify=1; fi if [ "$DEBUG" != "" ]; then echo "o `date` : Test results : Target is $state" fi fi if [ $notify -gt 0 ]; then DT=`date` echo | mail -s "$IP is $state" $ADDRESS fi sleep 300 done