Tomato多拨脚本

#!/bin/sh
GET_PPP_GATEWAY() {
         iface=$1
         echo "iface="$iface
         PPP_IP=$(ifconfig $iface|grep "inet addr"|awk -F ":" '{print $2}'|awk -F " " '{print $1}')
         PPP_GATEWAY=$PPP_IP
}
sleep 300
Hour=$(date +%H)
WAN1_IF=$(nvram get wan_iface)
WAN2_IF=$(nvram get wan2_iface)
WAN3_IF=$(nvram get wan3_iface)
WAN4_IF=$(nvram get wan4_iface)
if [[ "$WAN1_IF" == "" ] || [ "$WAN2_IF" == "" ] || [ "$WAN3_IF" == "" ]] && [ "$Hour" == "05" ] ; then
                 reboot
else
         GET_PPP_GATEWAY $WAN1_IF
         if [ "$PPP_IP" == "" ] && [ "$Hour" == "05" ] ; then
                 reboot
                 exit
         fi
         
         GET_PPP_GATEWAY $WAN2_IF
         if [ "$PPP_IP" == "" ] && [ "$Hour" == "05" ] ; then
                 reboot
                 exit
         fi        
         GET_PPP_GATEWAY $WAN3_IF
         if [ "$PPP_IP" == "" ] && [ "$Hour" == "05" ] ; then
                 reboot
                 exit
         fi        
         echo "X_WAN ok"
fi



#以下是四拨号允许两个拨号成功就不自动重启
#自动重启有次数限制,次数存放在NVRAM
#Powered by HeliXZz (c)2012
#!/bin/sh
GET_PPP_GATEWAY() {
        iface=$1
        echo "iface="$iface
        PPP_IP=$(ifconfig $iface|grep "inet addr"|awk -F ":" '{print $2}'|awk -F " " '{print $1}')
        PPP_GATEWAY=$PPP_IP
}
FAST_REBOOT() {
        service wan stop
        sleep 15
        kill -SIGHUP 1
}
sleep 35
TOTALNUM=4
WAN1_IF=$(nvram get wan_iface)
WAN2_IF=$(nvram get wan2_iface)
WAN3_IF=$(nvram get wan3_iface)
WAN4_IF=$(nvram get wan4_iface)
GET_PPP_GATEWAY $WAN1_IF
if [ "$PPP_IP" == "" ]; then
   let TOTALNUM=$TOTALNUM-1
fi
GET_PPP_GATEWAY $WAN2_IF
if [ "$PPP_IP" == "" ]; then
   let TOTALNUM=$TOTALNUM-1
fi
GET_PPP_GATEWAY $WAN3_IF
if [ "$PPP_IP" == "" ]; then
   let TOTALNUM=$TOTALNUM-1
fi
GET_PPP_GATEWAY $WAN4_IF
if [ "$PPP_IP" == "" ]; then
   let TOTALNUM=$TOTALNUM-1
fi
if [ $TOTALNUM -lt 3 ]; then
   if [ $(nvram get multiwan_retry_count) -lt 1 ]; then
      nvram set multiwan_retry_count=5
          FAST_REBOOT
   else
      RETRY_COUNT=$(nvram get multiwan_retry_count)
          let RETRY_COUNT=$RETRY_COUNT-1
          nvram set multiwan_retry_count=$RETRY_COUNT
          FAST_REBOOT
   fi
   exit
else
echo $TOTALNUM+"WAN ok"
nvram set multiwan_retry_count=5
fi

你可能感兴趣的:(Tomato多拨脚本)