#!/bin/sh PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin # We need to ping someone to see if it's up # We could try someone like Google who is likely to be up ... # HOST_TO_TEST=www.google.com # Or we could test our PPP peer (which seems like a better idea). If you have more than one PPP # connection, this will find the first which ifconfig reports. HOST_TO_TEST=`ifconfig -a|grep "inet addr"|grep "P-t-P" |head -1|cut -d":" -f3-|awk '{ print $1 }'` # How often do we do the test? If we test more often, we will find # the failure sooner. If we test too often, we'll be wasting CPU time # and bandwidth. 120 = 2 minutes TEST_FREQ=120 TEST_FREQ=20 # NUM_FAIL - how many times can it fail before restarting? NUM_FAIL=2 ################ function definitions ################### ppp_test() { ping -w 10 -c1 ${HOST_TO_TEST} > /dev/null 2>&1 return $? } ppp_start() { echo "Starting PPPd" pppd call adsl sleep 30 HOST_TO_TEST=`ifconfig -a|grep "inet addr"|grep "P-t-P" |cut -d":" -f3-|awk '{ print $1 }'` } ppp_kill() { pid=`pidof pppd` while [ ! -z $pid ]; do pid=`pidof pppd` kill -9 $pid sleep 2 done } ppp_check() { ppp_test if [ "$?" -ne "0" ]; then if [ "$1" -ge "$NUM_FAIL" ]; then echo "PPP Connection Down... restarting" ppp_kill sleep 20 ppp_start else echo "PPP Connection down? (Test $1 of $NUM_FAIL)" NF=`expr $1 + 1` sleep 20 ppp_check $NF fi fi } ########### starts here ############## if [ "$1" == "stop" ]; then echo "Shutting down PPPd" ppp_kill exit 0 fi # We assume that the firmware is loaded. # It needs to be loaded exactly once but there doesn't # seem to be a way of testing if it has already been loaded. # So this script assumes that the firmware is loaded, and # that pppd is probably running. # Or you can uncomment this line and make sure it points to your firmware: # /usr/local/sbin/modem_run -m -f /etc/ppp/mgmt.o while : do ppp_check 1 sleep $TEST_FREQ done