Listing 2 check-pppoe.sh shell procedure
#!/bin/bash
#
# Copyright Dick Munroe, munroe@csworks.com, 2005 all rights reserved.
#
# Use of this program is granted under the Gnu Public LIcense provided
# this copyright remains in place.
#
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
scriptName=${0##/*/}
scriptBaseName=${scriptName%%.*}
. /etc/$scriptBaseName/$scriptBaseName.conf
#
# Give the system some "time" to get ppp up. It may take longer than
# the default cycle and we don't want to get two ppp interface started.
#
sleep $SYSTEMSTARTUP
#
# Try a simple ppp restart. Power cyclying and other things are external
# to this logic. Call this only if the PPP interface really IS down.
#
function restartPPPoE()
{
I=0
while [ $I -lt $TRY ]
do
poff -r $DSL_PROVIDER 2>/dev/null || pon $DSL_PROVIDER
sleep $PPP_PAUSE
ifconfig $PPP >/dev/null 2>&1
theStatus=$?
#
# Bail if the interface is there
#
if [ $theStatus -eq 0 ]
then
return 0
fi
I=$(($I + 1))
done
return 1
}
#
# Record the pid in the run file
#
echo $$ >/var/run/$scriptBaseName.pid
powercycletime=$POWERCYCLETIME
while [ 1 -eq 1 ]
do
sleep $CYCLETIME
ifconfig $PPP >/dev/null 2>&1
theStatus=$?
if [ $theStatus -ne 0 ]
then
logger -p local2.warn $PPP has dropped, attempting restart
restartPPPoE
theStatus=$?
if [ $theStatus -ne 0 ]
then
#
# got here and the easy way didn't work, try cycling power,
# then restarting it.
#
logger -p local2.warn Cycling power on X10 interface $HOUSECODE.
br $HOUSECODE off
sleep $HOUSECODE_OFF_PAUSE
br $HOUSECODE on
sleep $HOUSECODE_ON_PAUSE
logger -p local2.warn $PPP still down after power cycle, \
attempting restart.
restartPPPoE
theStatus=$?
if [ $theStatus -eq 0 ]
then
powercycletime=$POWERCYCLETIME
logger -p local2.info $PPP is back up.
else
logger -p local2.emerg $PPP is not back up after $TRY, \
powercycle, $TRY attempts.
powercycletime=$(($powercycletime + $POWERCYCLETIMEINCREMENT))
if [ $powercycletime -gt $POWERCYCLETIMEMAXIMUM ]
then
powercycletime=$POWERCYCLETIMEMAXIMUM
fi
sleep ${powercycletime}s
fi
else
powercycletime=$POWERCYCLETIME
logger -p local2.info $PPP is back up.
fi
fi
done |