批量ping 检测linux主机是否可以通
批量ping 检测linux主机是否可以通
# 1、配置列表 [root@db137 liweiwie]# cat /home/dbatlbb/script/liweiwie/ping_ip.txt 192.168.120.109 192.168.120.110 192.168.120.113 192.168.120.123 192.168.10.222
[root@db137 liweiwie]#
# 2、脚本内容 [root@db137 liweiwie]# cat ping.sh #!/bin/bash # filename: /home/dbatlbb/script/liweiwie/ping.sh for ips in `cat /home/dbatlbb/script/liweiwie/ping_ip.txt` do result=`ping -w 2 -c 3 ${ips} | grep packet | awk -F" " '{print $6}'| awk -F"%" '{print $1}'| awk -F' ' '{print $1}'` if [ $result -eq 0 ]; then echo ""${ips}" is ok !" else echo ""${ips}" is not connected ....." fi done [root@db137 liweiwie]#
# 3、执行结果 [root@db137 liweiwie]# sh ping.sh 192.168.120.109 is ok ! 192.168.120.110 is ok ! 192.168.120.113 is ok ! 192.168.120.123 is ok ! 192.168.10.222 is not connected ..... [root@db137 liweiwie]#