I had two internet connection

1. Mtnl ( Gateway)
2. Tata ( 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


TSTIP="" # Any reliable Internet ip that responds to ping.
CURGW=`/sbin/route -n |awk '/^ {print $2 }'`

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

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