 #!/bin/sh
 #Script by KYM-NET
 #
 trap "kill -1 $PID" 1 2 3 
 TONE=off
 while sleep 2
 do
         set -- `ping -c 3 209.85.227.147 | grep loss`   # sends M5t just
 							   #  one package
         if [ "$4" != 0 ]
         then
 		if [ $TONE = on ]
 		then
 			date
 			echo "Connection to Internet  is back again" > /dev/tty1
 			date > /dev/tty1
 			echo "Connection to Internet is back at time below" >> /var/log/internet_link.log
 			date >> /var/log/internet_link.log
 			echo "The Internet Link is back again `date`. Automated Network Administration Script" | mail -s "Return of Internet Link" roykasa@gmail.com
			kill -1 $PID
 			TONE=off
 		fi
         elif [ $TONE = off ]
 	then
 		date
 		echo "Connection to Internet is lost" > /dev/tty1
		date > /dev/tty1
#		echo -e "\\33[10;500]\\33[11;500]"
 		echo "Connection to Internet is lost at time below" >> /var/log/internet_link.log
                date >> /var/log/internet_link.log
		echo "The Internet Link has Gone Down `date`. Automated Network Administration Script" | mail -s "Internet Link is Down" roykasa@gmail.com

 		while sleep 1; do echo -n "  Connection to Internet is lost!!  " > /dev/tty1 ; echo -e "\a" ; done &
 		PID=$!		# store background process pid
 		TONE=on
         fi
 done
 exit 0
