免费注册 查看新帖 |

Chinaunix

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

[proxy] 请教关于双线路由自动切换的shell [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-23 13:00 |只看该作者 |倒序浏览
自动切换 shell



#!/bin/sh
# edited by hb 2006.1
# set -x
#######################################################
PingConf='/root/monitor/pingIp'
LogDir='/root/monitor/pingLog'

#Define the interval time
INTERVAL='10'
########################################################
proc_main()
{
for i in `cat $PingConf`

   do
       IpAddress=$i
       ping -w20 $IpAddress -c 10 >errtmp
       if [ $? = 0 ] ; then
               rm errtmp
       else
               rm errtmp
               ErrTime=`date +%Y/%m/%d/%H:%M:%S`
               echo "$ErrTime"": ""$IpAddress"" cann't be connected">>$LogDir
#               sleep 1
#               cp /root/monitor/pingLog  /var/www/html/pingLog.html
               sleep 1
               sh -x /root/default               (default为一shell文件内容是#!/bash/sh
                         route replace default gw 211.111.111.111另一条线路网关作为默认网关)
       fi
    done
  }

##########################################################
# execute the proc_main function every the specified time INTERVAL
while [ "1" -eq "1" ]
do
     proc_main
     sleep $INTERVAL
done
就是ping /root/monitor/pingIp 文件里的ip地址,假如现在你用221.0.0.1/30ping网关221.0.0.2/30 一但221.0.0.2不通10个包后,服务器默认路由从221.111.111.111走,也就是你另一块网卡的网关。replace是替换。同时把ping不通的地址和时间以web形式由apache发布


这是别人写的关于双线自动切换的shell  我现在想把ping 该成arping  (arping ip -I eth0 -c 10)应该怎么做呢?

论坛徽章:
0
2 [报告]
发表于 2007-10-23 15:32 |只看该作者
原帖由 hackerdmf 于 2007-10-23 13:00 发表
自动切换 shell



#!/bin/sh
# edited by hb 2006.1
# set -x
#######################################################
PingConf='/root/monitor/pingIp'
LogDir='/root/monitor/pingLog'

#De ...


#!/bin/sh
# edited by hb 2006.1
# set -x
#######################################################
PingConf='/root/monitor/pingIp'
LogDir='/root/monitor/pingLog'

#Define the interval time
INTERVAL='10'
########################################################
proc_main()
{
for i in `cat $PingConf`

   do
       IpAddress=$i
       ping -w20 $IpAddress -c 10 >errtmp
    arping  $IpAddress -I eth0 -c 10 -w20 >errtmp
       if [ $? = 0 ] ; then
               rm errtmp
       else
               rm errtmp
               ErrTime=`date +%Y/%m/%d/%H:%M:%S`
               echo "$ErrTime"": ""$IpAddress"" cann't be connected">>$LogDir
#               sleep 1
#               cp /root/monitor/pingLog  /var/www/html/pingLog.html
               sleep 1
               sh -x /root/default               (default为一shell文件内容是#!/bash/sh
                         route replace default gw 211.111.111.111另一条线路网关作为默认网关)
       fi
    done
  }

##########################################################
# execute the proc_main function every the specified time INTERVAL
while [ "1" -eq "1" ]
do
     proc_main
     sleep $INTERVAL
done
就是ping /root/monitor/pingIp 文件里的ip地址,假如现在你用221.0.0.1/30ping网关221.0.0.2/30 一但221.0.0.2不通10个包后,服务器默认路由从221.111.111.111走,也就是你另一块网卡的网关。replace是替换。同时把 ping不通的地址和时间以web形式由apache发布
--------------------------------------------------------------------
应该差不多了.

论坛徽章:
0
3 [报告]
发表于 2007-10-23 15:32 |只看该作者
ping -w20 $IpAddress -c 10 >errtmp
被 arping  $IpAddress -I eth0 -c 10 -w20 >errtmp 替换掉就好了
具体lz自己测试下:)

论坛徽章:
0
4 [报告]
发表于 2007-10-26 22:01 |只看该作者
谢谢大家

论坛徽章:
0
5 [报告]
发表于 2007-10-26 22:02 |只看该作者
PingConf='/root/monitor/pingIp'  那这个要变吗?

论坛徽章:
0
6 [报告]
发表于 2009-05-27 18:34 |只看该作者
这个脚本怎么用?丢到crontab里?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP