免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: hackerdmf
打印 上一主题 下一主题

请教一个关于自动切换的shell(ping和arping) [复制链接]

论坛徽章:
0
11 [报告]
发表于 2007-10-23 14:24 |只看该作者
这里还有个脚本 我看不懂 麻烦大家看看
#!/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=""
tctgw=""
cncip=""
cncgw=""
lange=""
#==============================
#==============================
#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"s
done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP