#!/bin/sh # Script to poll ADSL at sane intervals and switch to dialup # service if necessary # Setup main path ADSLROOT=/root/adslswitch # Setup programs PING=/bin/ping IFUP=/sbin/ifup IFDOWN=/sbin/ifdown KILL=/bin/kill KILLALL=/usr/bin/killall PPPD=/usr/sbin/pppd PIDOF=/sbin/pidof ADSLSTART=/usr/sbin/adsl-start ADSLSTOP=/usr/sbin/adsl-stop SLEEP=/bin/sleep # Set default wait time between loops WAITTIME="1m" # Set Connection up test command CONNUP="$PING -w 10 -c 2 61.8.0.113" # Set the "test if adsl is up" command ADSLUP="$PIDOF pppoe" # Change to ADSLSwitch root cd $ADSLROOT while [ 1 -eq 1 ] do # Loop until otherwise notified DATE=`/bin/date` # Write timestamp to log echo "---- Testing ADSL at $DATE ----" >> adslswitch.log # Check if adsl is currently up if $ADSLUP && $CONNUP; then echo " * ADSL is up and working. Not doing anything..." >> adslswitch.log echo "---- Test Completed ---" >> adslswitch.log echo "*** SLEEPING FOR $WAITTIME ***" >> adslswitch.log else # Firstly, kill ADSL connection echo " * ADSL currently not working. Performing test..." >> adslswitch.log echo " * Killing current connection..." >> adslswitch.log $KILLALL pppd 2>> /dev/null $ADSLSTOP 2>> /dev/null $KILLALL pppoe 2>> /dev/null $KILLALL -9 pppd 2>> /dev/null $KILLALL -9 pppoe 2>> /dev/null $IFDOWN ppp0 2>> /dev/null # Dial ADSL connection echo " * Attempting to reconnect to ADSL..." >> adslswitch.log $ADSLSTART 2>> adslswitch.log # Ok, nested loop here is messy - I'll neaten it later if $CONNUP; then echo " * ADSL connection successfully established and working." >> adslswitch.log WAITTIME="1m" echo "---- ADSL test completed at $DATE ----" >> adslswitch.log echo "*** SLEEPING FOR $WAITTIME ***" >> adslswitch.log else echo " * ADSL connection failing. Attempting backup dialup service." >> adslswitch.log echo " * Killing dud ADSL connection (if exists)..." >> adslswitch.log $ADSLSTOP 2>> /dev/null $KILLALL pppd 2>> /dev/null $KILLALL pppoe 2>> /dev/null $KILLALL -9 pppd 2>> /dev/null $KILLALL -9 pppoe 2>> /dev/null $IFDOWN ppp0 2>> /dev/null echo " * Reconnecting to backup dialup service..." >> adslswitch.log $PPPD call pi 2>> adslswitch.log # Setting waittime to 30 mins for dialup test WAITTIME="30m" echo "---- ADSL test completed at $DATE ----" >> adslswitch.log echo "*** SLEEPING FOR $WAITTIME ***" >> adslswitch.log fi fi $SLEEP $WAITTIME done