TT双拨脚本

 

#!/bin/sh
GET_PPP_GATEWAY() {
        iface
=$1
        echo 
"iface="$iface
        PPP_IP
=$(ifconfig $iface|grep "inet addr"|awk -":" '{print $2}'|awk -" " '{print $1}')
        PPP_GATEWAY
=$PPP_IP
}

GET_PPP_GATEWAY2() {
        iface
=$1
        echo 
"iface="$iface
        PPP_IP2
=$(ifconfig $iface|grep "inet addr"|awk -":" '{print $2}'|awk -" " '{print $1}')
        PPP_GATEWAY2
=$PPP_IP2
}

FAST_REBOOT() {
#ISP要求重拨前必须先断开并且要间隔60秒才能拨号,如果无要求可以在下面2句前加上#
        #service wan stop
        #sleep 3
#快速重启命令,只是重新初始化Tomato DualWAN环境,硬件无需重启

        kill -SIGHUP 1
}


#开始检测WAN1, WAN2
WAN1_IF=$(nvram get wan_iface)
WAN2_IF
=$(nvram get wan2_iface)
GET_PPP_GATEWAY 
$WAN1_IF
GET_PPP_GATEWAY2 
$WAN2_IF
#初始化拨号次数
PPPDailNum=0
#循环,直到双拨成功
while [ "$PPP_IP" == "" ] || [ "$PPP_IP2" == "" ]
       
do
#拨号次数最多为10次
              if [ $PPPDailNum -ne  10 ]; then
                     FAST_REBOOT
                     let PPPDailNum
=PPPDailNum+1
#拨号后停顿,建议15秒以上
                     sleep 15
#不知道为什么需要重新获取一次才能够正常运行?
GET_PPP_GATEWAY() {
        iface
=$1
        echo 
"iface="$iface
        PPP_IP
=$(ifconfig $iface|grep "inet addr"|awk -":" '{print $2}'|awk -" " '{print $1}')
        PPP_GATEWAY
=$PPP_IP
}

GET_PPP_GATEWAY2() {
        iface
=$1
        echo 
"iface="$iface
        PPP_IP2
=$(ifconfig $iface|grep "inet addr"|awk -":" '{print $2}'|awk -" " '{print $1}')
        PPP_GATEWAY2
=$PPP_IP2
}
                     WAN1_IF
=$(nvram get wan_iface)
                     WAN2_IF
=$(nvram get wan2_iface)
                     GET_PPP_GATEWAY 
$WAN1_IF
                     GET_PPP_GATEWAY2 
$WAN2_IF
                     
#在SSH终端里面执行可以去掉注释看见IP获取情况
                     #echo $PPP_IP
                     #echo $PPP_IP2

              else
                    PPP_IP
="stop Dail"
                    PPP_IP2
="stop Dail"
             fi
done

 

posted on 2011-04-05 21:25  鬼蝶[DFCG]  阅读(923)  评论(0编辑  收藏  举报

导航