#! /bin/sh
IP=10.0.0.2
STATUS=UNKNOWN
LOG=/var/log/server-monitor.log

log()
{
	LINE="`date` :: $1"
	echo $LINE >> $LOG
	
}

log "Server monitor starts"

while [ 1 ]
do
	NEWSTATUS="UP"
	ping -c 1 $IP > /dev/null || NEWSTATUS="DOWN"
	
	if [[ "$NEWSTATUS" == "DOWN" && "$STATUS" != "DOWN" ]]; then
		log "$IP is down"
	fi
	
  if [[ "$NEWSTATUS" == "UP" && "$STATUS" == "DOWN" ]]; then
		log "$IP is up"
	fi
	
	STATUS=$NEWSTATUS
	sleep 10 || exit
done

