免费注册 查看新帖 |

Chinaunix

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

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

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-23 12:53 |只看该作者 |倒序浏览
自动切换 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 13:01 |只看该作者
24小时在线= 请问有人吗?

论坛徽章:
0
3 [报告]
发表于 2007-10-23 13:27 |只看该作者
替换这一句 " ping -w20 $IpAddress -c 10 >errtmp "  其中$IpAddress是IP地址

221.0.0.1/30ping网关221.0.0.2/30  是什么意思?子网掩码为什么会是30 ?

论坛徽章:
0
4 [报告]
发表于 2007-10-23 13:54 |只看该作者
具体怎么换呢 ?我想把ping换成arping

论坛徽章:
0
5 [报告]
发表于 2007-10-23 13:59 |只看该作者
arping $IpAddress -I eth0 -c 10>errtmp  不确定是否需要设定超时时间


感觉判断条件有问题,能把这两个命令运行结果贴出来吗
ping -w5 127.0.0.1 -c 3;echo $?;

ping -w5 117.1.1.3 -c 3;echo $?;

[ 本帖最后由 AT 于 2007-10-23 14:11 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2007-10-23 14:03 |只看该作者
-c 10   表示arping10次  因该就不需要时间设置了   着个脚本我具体没做环境测试。最近准备把硬件路由换成linux的软件路由

论坛徽章:
0
7 [报告]
发表于 2007-10-23 14:06 |只看该作者
[root@www ~]# ping -w5 127.0.0.1 -c 3;echo $?;
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.043 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.016 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.015 ms

--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.015/0.024/0.043/0.014 ms, pipe 2
0
[root@www ~]#

这个是我随便了个linux的主机 测试的这一个命令

论坛徽章:
0
8 [报告]
发表于 2007-10-23 14:08 |只看该作者
[root@www ~]# ping -w5 117.1.1.3 -c 3;echo $?;
PING 117.1.1.3 (117.1.1.3) 56(84) bytes of data.
From 192.168.1.235 icmp_seq=1 Destination Host Unreachable
From 192.168.1.235 icmp_seq=2 Destination Host Unreachable
From 192.168.1.235 icmp_seq=3 Destination Host Unreachable

--- 117.1.1.3 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2999ms
, pipe 4
1
[root@www ~]#

论坛徽章:
0
9 [报告]
发表于 2007-10-23 14:10 |只看该作者
谢谢,脚本的判断没有问题

论坛徽章:
0
10 [报告]
发表于 2007-10-23 14:12 |只看该作者
应该是我感谢你才对。我以前只做单线的linux路由  现在要做个双线的 还真不知道该怎么做了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP