root@time:~# cat autorecon.sh #!/bin/bash SLEEP=60 GATEWAY=$(ip addr show dev ppp0 | \ sed -n 3p | \ awk '{ print $4 }' | \ sed -e 's:/[0-9]*::' \ ) #TIMER=/var/run/autorecon.timer TIMER=/tmp/autorecon.timer # for non-root tests PASS=0 do_dnsstuff() { # Whatever ;) echo "DNS stuff..." } do_pass() { ((PASS++)) echo $(($(date +%s)+($SLEEP*2+5))) > $TIMER echo $PASS >> $TIMER take_action } take_action() { # Here are the reconnect attemps number and actions to take. case $PASS in 2|4|5|6) /etc/init.d/dial start;; 3) /etc/init.d/natfire restart;; 7) reboot;; esac exit -$PASS } if [ -e $TIMER ]; then if [ $(date +%s) -lt $(sed -n "1p" $TIMER) ]; then PASS=$(sed -n "2p" $TIMER) rm $TIMER else rm $TIMER fi fi # See if the ATM bridge or pppd died. if [ -z $(pidof pppd) ] || [ -z $(pidof br2684ctl) ]; then echo "pppd or ATM bridge died." do_pass fi # See if ppp0 exist in the links. if [ -z $GATEWAY ]; then echo "ppp0 does not exist." do_pass fi # If ping fails, take actions. ping -c3 $GATEWAY || do_pass # If DNS fails, take actions for DNS. host google.com || do_dnsstuff exit 0 root@time:~#