Script to restart ADSL if it's down

Results 1 to 3 of 3

Thread: Script to restart ADSL if it's down

  1. #1
    X_console Guest

    Script to restart ADSL if it's down

    I thought I'd share this with everyone. I'm not sure if there's already something like this on the Net... probably is but I was too lazy to look around so I wrote my own.

    Anyways, the following script will check to see if your ADSL connection is up and running. If it's not, it restarts it for you. It performs two checks. First to see if the PID of your ADSL client is running, and if it is, it checks to see if you can actually ping servers on the Net. If it fails either the first or second check, the connection is restarted. I recommend having it started from root's crontab:

    * * * * * /usr/local/sbin/adsl-restart 2> /dev/null 1> /dev/null

    Now for the script:

    # adsl-restart - Restarts an ADSL connection if it's not active.
    # This program is tailored for the Roaring Penguin PPPoE client.
    # X_console <>
    # firewall script:
    # servers to ping in order to determine if we have an active
    # connection. you must NOT put in a machine that is in your LAN!
    # make sure the server is somewhere on the Internet and that it does
    # not block pings:
    # this variable reflects on the total number of servers
    # you want to ping:
    # this is a counter to determine how many servers responded
    # to the ping sent:
    # restart() restarts the ADSL connection:
            # connection is down. we need to restart it along
            # with the firewall script:
            /usr/sbin/adsl-stop; wait
            echo "Activating ADSL connection..."
            /usr/sbin/adsl-start; wait
    # CHECK 1: see if the ADSL process is running:
    if [ ! -f /var/run/ ]; then
            # connection is not running, so we restart it:
            # it looks like the PID is still there, but sometimes
            # we still can't access the Net... so we move on to
            # CHECK 2...
            # CHECK 2: start pinging each of the servers:
            for server in $S1 $S2 $S3 $S4 $S5; do
                    # we send one ping request to each server. if all or any of
                    # the servers respond, then the connection is up. if none of
                    # them respond, then we restart the connection:
                    printf "Now pinging $server...\n"
                    ping -c1 $server 1>&2 > /dev/null
                    if [ "$?" -eq 0 ]; then # server responded!
                            printf "Response from $server\n"
                            response=$((response + 1));
                            printf "No response from $server\n"
                            response=$((response + 0));
            # if the response is greater than 0, then the ADSL connection
            # is up. if it's 0, then we have to restart the ADSL connection:
            if [ "$response" -gt 0 ]; then
                    # ADSL connection is up so we exit:
                    exit 0
                    # ADSL connection is down, so we restart it:
    By the way, the above was made for the Roaring Penguin PPPoE client... it can probably be modified to suit your PPPoE client though.

  2. #2
    Join Date
    Jun 2007

    Smile error mesages name is Andrei and I have used your script but seems it doesn't work on Mandriva 2006.Can you please send me a working script for Mandriva 2006 ?.Thx.
    Last edited by andreiu; 06-25-2007 at 09:43 AM.

  3. #3
    Join Date
    Sep 2003
    Rochester, MN
    Well, this is a very old thread and the user that originally posted it doesn't frequent JustLinux anymore. I don't use ADSL myself, but glancing through the script it looks like you'll need to alter the restart function and possibly the "if [ ! -f /var/run/ ]; then" line since those two things will probably be different now in Mandriva. Basically figure out how you would normally restart your connection and then stick those commands in the restart function, and maybe even remove the check for whether it's running entirely, since I suspect it's not necessary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.