#!/bin/bash
#
# netpoll.sh - Small script to log if your network goes up and down.
#
# Copyright (C) 2002 Oskar Andreasson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# $Id: netpoll.sh,v 1.2 2003/09/09 14:10:05 blueflux Exp $


NETHOST="www.not-a-host.not"

LOG="/home/blueflux/netpoll.log"
DOWNLOG="/home/blueflux/downtime.log"

UP=1

while true ; do
	ping -c 3 $NETHOST 1> /dev/null 2> /dev/null
	if [ $? != 0 ] ; then
		echo "`date +%D-%T` $NETHOST is down" >> $LOG
		if [ $UP == 0 ] ; then
			echo "`date +%D-%T` $NETHOST went down" >> $DOWNLOG
		fi
		UP=1
	else
		echo "`date +%D-%T` $NETHOST is up" >> $LOG
		if [ $UP == 1 ] ; then
			echo "`date +%D-%T` $NETHOST went up" >> $DOWNLOG
		fi
		UP=0
	fi
	sleep 60
done
