您的位置:首页 > 其它

3004.脚本作业―l201.2.0编写一个脚本用于检测IP地址(递进版2)

2012-04-27 00:58 281 查看
l201.2.0: 在linux01a中编写一个脚本,用于检测IP地址是否能够PING通

(一次发3个包,其中任一个能够ping通,则认为此IP能够ping通)

脚本命名:l201.2.0.ping.sh 小版本改进编号: l201.2.x.ping.sh x从0,1,2,3递增

环境说明:
linux01a中有IP地址 192.168.0.1,192.168.0.31,192.168.0.41
linux01b中有IP地址 192.168.0.2,192.168.0.51,192.168.0.61
在实验前,应先检查以上地址均能够ping通.

在命令行下执行ping命令,如果IP地址能够ping通(只要有一个包能PING通即可),则如下显示
[root@linux01 ~]# ping -c 3 192.168.0.31
PING 192.168.0.31 (192.168.0.31) 56(84) bytes of data.
64 bytes from 192.168.0.31: icmp_seq=1 ttl=128 time=0.177 ms
64 bytes from 192.168.0.31: icmp_seq=2 ttl=128 time=0.317 ms
64 bytes from 192.168.0.31: icmp_seq=3 ttl=128 time=0.133 ms

--- 192.168.0.31 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.133/0.209/0.317/0.078 ms

在命令行下执行ping命令,如果IP地址不能够ping通(3个包均不通),则如下显示
[root@linux01 ~]# ping -c 3 192.168.0.100
PING 192.168.0.100 (192.168.0.100) 56(84) bytes of data.
From 192.168.0.11 icmp_seq=1 Destination Host Unreachable
From 192.168.0.11 icmp_seq=2 Destination Host Unreachable
From 192.168.0.11 icmp_seq=3 Destination Host Unreachable

--- 192.168.0.100 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2001ms
, pipe 3

脚本要求:
编写一个shell脚本,执行脚本后自动ping以下地址:192.168.0.1,192.168.0.31,192.168.0.2,192.168,0.91
以上IP地址直接写在脚本之中。执行完成后,应显示能够ping通的IP地址和不能够ping通的IP地址。
根据环境的IP配置,能ping通的IP地址有192.168.0.1,192.168.0.31,192.168.0.2
不能ping通的IP地址有192.168.0.91

注:ping命令发3个包,只要其中一个包能ping通,则可认为此IP能够ping通

附件是脚本实验环境拓扑图.

shell脚本系列视频访问链接:
(一)shell脚本与应用示例
(二)三剑客—文本处理
(三)千机变—脚本变量
(四)向左向右—条件选择
(五)望山跑死马—循环
(六)脚本函数与任务调度

本文出自 “培训师李明峻” 博客,请务必保留此出处http://sop2008.blog.51cto.com/71724/845397
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: