So many times I've search the 'net for a simple network uptime script. I always wanted to know the exact time the network went down (and came back up) so that I could track down the cause of the problem. Here is a dead-simple script that will do just that:
## connect_test.sh ##
## This script continually pings an IP address / hostname and reports *only*
## when it is unable to reach the destination.
## Example: ./connect_test.sh www.google.com
if [[ $1 == "" ]];
echo "Please provide an IP/host to ping"
while [ true ]; do
p=`ping -c 4 $1 > /dev/null 2>&1`
if [[ $? != 0 ]];
echo "Unable to reach $1 at $d"
It works best if you open up multiple terminal windows and try to connect to different portions of your network simultaneously. For example:
./connect_test.sh [my neighboring workstation]
./connect_test.sh [my gateway]
./connect_test.sh [my ISPs DNS]
./connect_test.sh [random domain - ie. google.com or yahoo.com]
This way, you can determine exactly where the failure is AND you have a record of the time it occurred. Hope that helps!