免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1522 | 回复: 1
打印 上一主题 下一主题

双线切换shell 后的一点小问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-14 21:55 |只看该作者 |倒序浏览
#!/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不能切换到默认路由 所以就不能正常访问

论坛徽章:
0
2 [报告]
发表于 2008-05-15 11:38 |只看该作者
现在我想在做一个脚本让它检测$cncgw  如果通 责更改aaa表网关为cncgw 如果不通则更改为tctgw
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP