Learnings

Thursday, May 13, 2010

Shell script: To check network and perform some action when dead

#set -x

while [ 1=1 ]
do
sleep 5
ping -n 1 www.google.com > ping.result
n=`cat ping.result | grep -c -e 'could not find' -e 'unreachable' -e 'error'`
# echo "Value of n is $n, disc is $disc"
if [ "$n" -ne "0" ]
then
echo `date | awk '{print $4}'`---
if [ "$disc" != "1" ]
then
echo "Disconnecting..."
`artdial.exe /d`
echo "Disconnected"
fi
disc=1
else
echo `date | awk '{print $4}'` +++
if [ "$disc" != "0" ]
then
# Wait a while before trying to connect
sleep 5
echo "Connecting..."
`artdial.exe /u:ramakv@in.ibm.com /p:nA15ch3n Wecm Bangalore`
dc=$?
disc=$dc
echo "...Connected"
fi
fi
done

0 Comments:

Post a Comment

<< Home