#!/bin/sh # If another instance of this script is running, then exit RETURNVAL=`ps -C adsl-autoconect.sh | wc -l` if [ "$RETURNVAL" -ne "3" ] ; then echo "Aborting... another instance is already running." exit 1 fi debug=false delay=15 while getopts t:d o do case "$o" in t) delay=$OPTARG;; d) debug=true;; [?]) print >&2 "Usage: $0 [-t TimeDelay] -d\n-d Debug mode" exit 1;; esac done # poff while true ;do if $debug ; then ( echo "ping." ) fi TIMEOUT=3 RESULT=`ping -q -r -c 2 www.voila.fr >/dev/null 2>&1 & CMDPID=$! (sleep $TIMEOUT; kill -9 $CMDPID) & WATCHDOGPID=$! wait $CMDPID >/dev/null 2>&1 # wait for command kill $WATCHDOGPID >/dev/null 2>&1` # Test the exit code of the ping for success/failure. if [ $? -eq 1 ] ; then if $debug ; then ( echo "Ping OK." ) fi if $debug ; then ( echo "Attente $delays." ) fi I=0 while [ $I -lt $delay ] ; do I=$[$I+1] sleep 1; if $debug ; then ( echo "-$I-") fi done #if $debug ; then ( echo "Restore iptables" ) fi #iptables-restore /root/myiptables.save if $debug ; then ( echo "goto debut." ) fi else if $debug ; then ( echo "Ping ERROR." ) fi pon if $debug ; then ( echo "Adsl start" ) fi echo 1 > /proc/sys/net/ipv4/ip_forward if $debug ; then ( echo "Ip_forward 1" ) fi iptables-restore /root/myiptables.save if $debug ; then ( echo "Restore iptables" ) fi sleep 4 fi done