Hi all the list,

I am happy to tell you that I have the solution for this recurent problem.
Many thanks for all of you, and for Jacques who has sent me a very intersting script.
Jacques has explained me how to play with 'cron' to launch this script every minute.

Sorry for the cuting at each end of line, due to my mailer editor...
I believe that you will correct this for your usage.

#!/bin/sh
#
# Check a regular interval defined in /etc/crontab that IP exists for IFACE
# and that IP has not changed
# this is obtained by scanning "ip addr show $IFACE" return (function getip()).
# If IFACE is down or IP has changed, then a script can be executed.
# Return to correct defaultroute if IPSEc user lost ISP link.

# Adapted by J. Nilo from a script by T. Nkaoua
# Defaultroute switching survey feature added by F6HQZ Francois BERGERET 
# (tks to J.Nilo and T.Nkaoua)

IFACE=ppp0
FILE=/tmp/checkip

getip() {
        IP=`ip addr show $IFACE | grep inet | cut -f1 -d"p" | cut -f2 -d"t" | cut -f1 
-d"/"`
}

getgate() {
        GATE=`ip addr show $IFACE | grep inet | cut -f1 -d"/" | cut -f2 -d"r" | cut 
-f1 -d"/"`
}

getdefroute() {
        DEFROUTE=`ip route | grep default | cut -f3 -d"v"`
}

if [ -f $FILE ]; then
        read OLDIP < $FILE
else
        getip
        echo $IP > $FILE
        exit
fi

getip
echo $IP > $FILE
getgate
getdefroute

if ! [ "$IP" ]; then
        logger "checkip: Checkip connection broken detection"
#
# Put any command here that you want to activate if IFACE is down
#
        exit
fi

if   [ $DEFROUTE != $IFACE ]; then
        logger checkip: IP:$IP GATE:$GATE DEFAULTROUTE:$DEFROUTE
        logger checkip: WARNING: defaultroute was $DEFROUTE
        logger checkip: ip route del default
        logger checkip: ip route add default via $GATE dev $IFACE
        ip route del default
        ip route add default via $GATE dev $IFACE
        exit
fi

if [ $OLDIP != $IP ]; then
        logger checkip: IP has changed for $IFACE: new IP is $IP - old IP was $OLDIP
#
# Put any command here that you want to activate if IP has changed
#
        logger checkip: ip route del default
        logger checkip: ip route add default via $GATE dev $IFACE
        ip route del default
        ip route add default via $GATE dev $IFACE
fi

#------------------------ FILE END ----------------------------------- 

Instructions to install checkip.dat :

Copy this file to : 
/usr/sbin/checkip.dat

chmod 755 checkip.dat

Edit /etc/cron.d/multicron and add a new line :
*/1     * * * * root    /usr/sbin/checkip.dat

Backup root.lrp

And enjoy with Bering running 24/24 without any interruption due to ISP link cutted !

Best Regards,
Francois BERGERET,
France.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html

Reply via email to