miércoles, 1 de enero de 2014

Keeps dsl-provider connected on GNU/Linux

Hey everybody, here I made a Bash Script that restore the connection if it's broken, i hope it is useful, enjoy!


#!/bin/bash
if [ $(whoami) = 'root' ]
then
    rest=0
    salir=0
    while [ $salir = 0 ]
    do
        ip r | grep .
        if [ $? = 1 ]
        then
            # Verifying that eth0 is setted up
            ip link show dev eth0 | grep "state UP"
            if [ $? = 1 ]
            then
                echo "Check your modem and cables"
                salir=1;
            else
                echo "Connection down, attempting to reconnect..."
                #### Begin - PPPoE Connection Commands
                poff dsl-provider # Cleaning.
                pon dsl-provider
                #### End - PPPoE Connection Commands
                clear
                if [ $rest = 0 ]
                then
                    rest=1
                else
                    if [ $rest > 1 ]
                    then
                        echo "re-connection command issued ("$rest " times)"
                        echo "hoping for the best"
                    fi
                fi
                rest=$(expr $rest + 1)
                # wait for 10 seconds, to not saturate the cpu.
                sleep 10;
            fi
        else
            echo "Connection Established"
        fi
    done
else
    echo 'You are not root, try again being root user'
fi

if [ $salir = 1 ]
then
    exit 1
else
    exit 0
fi

To use it, just copy it and paste into a .sh new file.

You are able to modify it and share it!

As always, sorry my English!

Regards!

No hay comentarios:

Publicar un comentario