Friday, March 27, 2009 (Yet another one)

I have posted two versions of my script. (The one that checks if I have been disconnected from the net and reconnects)

Here's the latest one. It is now capable of checking if one instance is already running, and won't start another one unnecessarily:

#echo "Going Online..."
#/usr/local/bin/ > /dev/null
trap "{ echo $0 removing lock; rm -f $LOCKFILE; exit 255; }" SIGINT SIGTERM
if [ -f $LOCKFILE ]; then
echo "$0: already running, exiting..."
exit 1
while true; do
ping -c 2 -W 120 > /dev/null

if [ "$?" = "0" ]; then
echo "You are connected"
/usr/local/bin/ > /dev/null
echo "Disconnect detected at `date`, reconnecting" >> /home/akshay/logs/keeponline.log
sleep 10m

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: