Friday, September 12, 2008

Alternate approach to 'keeponline'

Instead of running the 'keeponline' script (described here) as a cron job, I decided to make it run as a standalone script. (Because the cron job kept spamming my syslog file)

The new /usr/local/bin/ looks like this:

echo "Going Online..."
/usr/local/bin/ > /dev/null
while true; do
ping -c 1 -W 120 > /dev/null

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

Next I make another script, keeponline-launch inside /etc/network/if-up.d/


# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

sh /usr/local/bin/ &

exit 0

This will basically launch the keeponline script when the network interface comes up :)

(Thanks to Vivaldi Gloria from ubuntuforums)

No comments: