2008下半年软考指定用书鸟哥的LINUX私房菜Linux命令、编辑器与Shell编程新蛋中国购物
发新话题
打印

双线切换shell后的一点小问题

双线切换shell后的一点小问题

#!/bin/sh
#=============================
#Script Nameaker`s both WAN guard Shell for Linux
#Author: Daker
#Version: 3.5
#RUL:http://dakerbt.spaces.live.com
#=============================
#=============================
#Both WAN IPaddress/gateway config
tctip="61.236.234.53"
tctgw="61.236.234.49"
cncip="192.168.8.11"
cncgw="192.168.8.1"
lange="10"
#==============================
#==============================
#Both WAN Log config
entry="100"
#==============================
if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $tctgw`" ]; then   
line="checl"
else   
line="cnc"
fi
while true;
do
tctok="$(ping -c 1 $tctgw|grep "100% packet loss"|wc -l)"
cncok="$(ping -c 1 $cncgw|grep "100% packet loss"|wc -l)"
if [ $tctok -eq 0 ] && [ $cncok -eq 0 ] && [ $line != "checl" ]; then
echo "start checl"
date '+#Both network connected. %D %X' >>\log\checl.log
   if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $cncgw`" ]; then
      ip r re 0/0 via $tctgw
   fi
   if [ -n "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then
      route del -host $tctip gw $cncgw
   fi
   if [ -n "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then
      route del -host $cncip gw $tctgw
   fi
line="checl"
elif [ $tctok -eq 1 ] && [ $line != "cnc" ]; then
echo "start cnc"
date '+#disconnected from tct. %D %X' >>\log\checl.log
     if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $tctgw`" ]; then
        ip r re 0/0 via $cncgw
     fi
     if [ -n "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then
        route del -host $cncip gw $tctgw
     fi
     if [ -z "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then
        route add -host $tctip gw $cncgw
     fi
line="cnc"
elif [ $cncok -eq 1 ] &&  [ $line != "tct" ]; then
echo "start tct"
date '+#disconnected from cnc. %D %X' >>\log\checl.log
     if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $cncgw`" ]; then
        ip r re 0/0 via $tctgw
     fi
     if [ -n "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then
        route del -host $tctip gw $cncgw
     fi
     if [ -z "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then
        route add -host $cncip gw $tctgw
     fi
line="tct"
fi
if [ -e \log\checl.log ];then
logok="$(grep "#" \log\checl.log|wc -l)"
   if [ $logok -ge $entry ];then
      rm \log\checl.log -f
   fi
fi
sleep "$lange"
done

这是我 的双线的shell  执行后 默认的路由网关 变tctgw 现在有一个问题是

如果2条线都通 的话会各自走自己的路由 比如192.168.1.1 走路由表aaa (aaa的网关为cncgw) 2条线都通的情况下192.168.1.1 访问正常
如果tctgw不通了责自动切换到cncgw  192.168.1.1 访问正常

如果cncgw不通了 那么自动切换到tcggw路由  192.168.1.1 还是要走路由表aaa的网关cncgw 那么192.168.1.1就不能正常访问了
也就是 如果默认网关通的话,而路由表aaa的网关不通的话  本来定义走aaa的ip不能切换到默认路由 所以就不能正常访问
发新话题