标签:color span else 12月 col chm amp status hosts
1、用ping命令编写脚本来查询一组IP地址同时检查他们是否处于活动状态
1 [zhi@centos7 ~]$ vi CheckHostStatus.sh 2 [zhi@centos7 ~]$ ll 3 总用量 4 4 -rw-rw-r-- 1 zhi zhi 284 12月 5 21:49 CheckHostStatus.sh 5 [zhi@centos7 ~]$ cat CheckHostStatus.sh 6 #!/bin/bash 7 #文件名:CheckHostStatus.sh 8 #用途:检查一组IP地址同时检查他们是否处于活动状态: 9 for ip in 192.168.2.{1..255}; 10 do 11 ping $ip -c 1 &> /dev/null; 12 if [ $? -eq 0 ]; 13 then 14 echo $ip is alive 15 else 16 echo $ip is no alive 17 18 fi 19 20 done 21 22 [zhi@centos7 ~]$ chmod 755 CheckHostStatus.sh 23 [zhi@centos7 ~]$ ls 24 CheckHostStatus.sh 25 [zhi@centos7 ~]$ ./CheckHostStatus.sh 26 192.168.2.1 is alive 27 192.168.2.2 is no alive 28 192.168.2.3 is no alive 29 192.168.2.4 is no alive
标签:color span else 12月 col chm amp status hosts
原文地址:http://www.cnblogs.com/me80/p/7989626.html