[ale] DSL restart Script

Guillaume triton at madchat.org
Wed Sep 12 00:20:44 EDT 2001


thoses of you who host a server on a dynamic ip might be
interested in this nasty script ;)

#! /bin/sh
# dsl restart based on .pid, net pings and your ip/dynamic sub.domain

# check .pid=ps|grep.pppd /> check yourIP=yourdyn.dom /> restart dyndns client
# if not twice, /> pings on the net /> if not, restart dsl, dynclient and loop 
# /etc/crontab example for checks every 9 min:  */9 * * * *  root    /etc/cron.d/cronpppoe   (then: /etc/init.d/crond restart)

# name of your start/stop pppoe script - you can enter pppoe command lines
# and/or simply kill the pid to stop: kill `cat /var/run/ppp?.pid` and pppoe restart
DSLSTART="adsl-start";
DSLSTOP="adsl-stop";
HOSTEDDOM="eboga.d2g.com";
DYNDSTART="/usr/local/bin/dns2go /server/key";
DYNDSTOP="killall -9 dns2go";
PING1="madchat.org";
PING1IP="213.186.34.76";
PING2="google.com";
PING2IP="216.239.35.100";
COUNTER=1;

while [ $COUNTER -le 5 ]; do

if ps xww | grep pppd | grep `cat /var/run/ppp?.pid`; then

    IP="`ifconfig ppp0|grep inet|awk '{print $2}'|awk -F":" '{print $2}'`";
    if ping $HOSTEDDOM -c 2 -w 10 | grep $IP; then
		    echo "ping @ $HOSTEDDOM ok. Exiting. $IP";
    logger -t "cronpppoe" ping @ $HOSTEDDOM ok. Exiting. $IP;
    exit 0;

    else
	$DYNDSTOP;
	$DYNDSTART;
	sleep 10;
        IP="`ifconfig ppp0|grep inet|awk '{print $2}'|awk -F":" '{print $2}'`";
	if ping $HOSTEDDOM -c 2 -w 10 | grep $IP; then
	                   echo "dyndns restarted. ping @ $HOSTEDDOM ok. Exiting. $IP";
	logger -t "*! cronpppoe" dyndns restarted. ping @ $HOSTEDDOM ok. Exiting. $IP;
	exit 0;

        else
	    $DYNDSTOP;
            $DYNDSTART;
            sleep 20;
    	    IP="`ifconfig ppp0|grep inet|awk '{print $2}'|awk -F":" '{print $2}'`";
	    if ping $HOSTEDDOM -c 2 -w 10 | grep $IP; then
	                       echo "dyndns restarted 2x. ping @ $HOSTEDDOM ok. Exiting. $IP";
	    logger -t "*! cronpppoe" dyndns restarted 2x. ping @ $HOSTEDDOM ok. Exiting. $IP;
	    exit 0;

	    else
		if ping $PING1 -c 2 -w 10 | grep $PING1IP; then
    	    	                   echo "dyndns server restarted 2x and DOWN. ping @ $PING1 ok. Exiting. $IP";
    		logger -t "*! cronpppoe" dyndns server restarted 2x and DOWN. ping @ $PING1 ok. Exiting. $IP;
		exit 0;
	
		else
		    if ping $PING2 -c 2 -w 10 | grep $PING2IP; then
		                       echo "dyndns server restarted 2x and DOWN. ping @ $PING1 DOWN. ping @ $PING2 ok. Exiting. $IP";
    	    	    logger -t "*! cronpppoe" dyndns server restarted 2x and DOWN. ping @ $PING1 DOWN. ping @ $PING2 ok. Exiting. $IP;
        	    exit 0;
						    
		    else
		    $DSLSTOP;
		    $DSLSTART;
		    sleep 2;
		    $DYNDSTOP;
		    $DYNDSTART; 
		    echo "$COUNTER";
		    logger -t "*! cronpppoe" cycle $COUNTER. DSL RESTARTED. sleep 10s, looping;
		    let $[ COUNTER += 1];

		    sleep 10;
		
		    fi
		fi
	    fi
	fi
    fi

else
$DSLSTOP;
$DSLSTART;
sleep 2;
$DYNDSTOP;
$DYNDSTART;
                   echo "ppp .pid dead. DSL restarted. sleep 10 b4 check.";
logger -t "*! cronpppoe" ppp .pid dead. DSL restarted. sleep 10 b4 check.;
sleep 10;
fi									          

done

echo "$COUNTER cycles done. DSL DOWN. Exiting.";
logger -t "*! cronpppoe" $COUNTER cycles done. DSL DOWN. Exiting.;







More information about the Ale mailing list