I had two internet connection

1. Mtnl (192.168.0.1 Gateway)
2. Tata (192.168.1.2 Gateway

Mtnl isp connection is on DSL 502t small adsl modem & Tata isp connection is on Zyxel P-600 series modem

I had configured both isps connection on ubantu 11.04 desktop edition, my internet works fine but i can use only one connection at a time so we want to use mtnl isp connection as a backup connection

I had downloaded 2 or 3 scripts from internet and tested on both connection it successfully give backup of second connection but only when you swith off the modem it cannot switch the second gateway when i had pulled out the adsl connection cable for testing.

It means the failover scripts only works when I switch off the modem, I need a failover script which works when the adsl means the internet line goes off not to when i switch of the modem

Here is the script which i had tested but not works as a backup

Script

#!/bin/bash
GW1="192.168.0.1"
GW2="192.168.1.2"
TSTIP="59.185.3.10" # Any reliable Internet ip that responds to ping.
CURGW=`/sbin/route -n |awk '/^0.0.0.0/ {print $2 }'`

if ping -w2 -c3 $TESTIP >/dev/null 2>&1; then
echo "Active ISP is Ok."
else
if [ "$CURGW" = "$GW1" ]; then
NEWGW="$GW2"
else
NEWGW="$GW1"
fi
/sbin/route del default
/sbin/route add default gw $NEWGW
fi

Please provide me the best script which will work as a isp failover