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脚本系列视频访问链接: