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:
By the way, the above was made for the Roaring Penguin PPPoE client... it can probably be modified to suit your PPPoE client though.
# adsl-restart - Restarts an ADSL connection if it's not active.
# This program is tailored for the Roaring Penguin PPPoE client.
# X_console <email@example.com>
# 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:
echo "Activating ADSL connection..."
# CHECK 1: see if the ADSL process is running:
if [ ! -f /var/run/adsl.pid ]; 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:
# ADSL connection is down, so we restart it:
Hi.my 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 10:43 AM.
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/adsl.pid ]; 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.