Tuesday, February 1, 2011

BASH : Network Check

touch networkcheck.sh -> checks internet connectivity like 'ping -c 2 www.google.com' -> send 2 packets
#!/bin/bash
if [ $# -eq 0 ]
then
SITE="www.google.com"
else
SITE="$1" # we have 1 argument given when we run the script
fi
ping -c 2 $SITE > /dev/null
if [ $? != 0]
then
echo `date +%F`
echo There seems to be internet connectivity problems!
cat log.`date +%F` | mail -s "there are internet problems" root
fi
#cron the unix scheduale
#END
chmod u+x networkcheck.sh
./networkcheck.sh > pingfile.`date +%F`
./networkcheck.sh 192.168.1.1 -> result is ok
./networkcheck.sh 192.168.1.1 > pinglog.'date +%F'
./networkcheck.sh 192.168.1.23 -> results connectivity issue


ls -l /etc/cron.daily
ls -l /etc/init.d/ -> scripts that examin the system

No comments:

Post a Comment