Here's the latest one. It is now capable of checking if one instance is already running, and won't start another one unnecessarily:
#!/bin/bash
#echo "Going Online..."
#/usr/local/bin/online.sh > /dev/null
LOCKFILE="/var/lock/keeponline.lock"
trap "{ echo $0 removing lock; rm -f $LOCKFILE; exit 255; }" SIGINT SIGTERM
if [ -f $LOCKFILE ]; then
echo "$0: already running, exiting..."
exit 1
fi
touch $LOCKFILE
while true; do
ping -c 2 -W 120 www.google.com > /dev/null
if [ "$?" = "0" ]; then
echo "You are connected"
else
/usr/local/bin/online.sh > /dev/null
echo "Disconnect detected at `date`, reconnecting" >> /home/akshay/logs/keeponline.log
fi
sleep 10m
done
There is no real use for this script, since SuperSify provides this feature. But I found that my version has less number of false positives when the bandwidth is completely choked. Besides, I just wanted to learn how to use traps :)
No comments:
Post a Comment