tisdag, februari 21, 2012

CRON job to keep OpenWRT 3G connection alive

This is the CRON job that I use to keep the 3G connection on my OpenWRT setup alive. It is probably not the most correct way to accomplish this and I'm eager to hear suggestions on improvements from other users out there. Here goes:

#!/bin/sh
IFCONFIG="/sbin/ifconfig 3g-wan";

ISIT=`$IFCONFIG | grep "UP" | wc -l`;

if test $ISIT -gt 0; then
        if ! ping -q -c 1 -W 10 -I 3g-wan www.sunet.se > /dev/null; then
                #(ifdown wan; ifup wan) &
                /etc/init.d/network3g restart &
        fi
fi

And my crontab looks like this, runs the script every five minutes:

*/5 * * * * /bin/tester.sh

1 kommentar:

Marcus sa...

Sweet

I'm thinking of changing www.sunet.se to 8.8.8.8 (google pub dns) but maybe you want a restart if dns lookup fails.