批量ping 检测linux主机是否可以通
# 1、配置列表[root@db137 liweiwie]# cat /home/dbatlbb/script/liweiwie/ping_ip.txt192.168.120.109192.168.120.110192.168.120.113192.168.120.123192.168.10.222 [root@db137 liweiwie]#
# 2、脚本内容[root@db137 liweiwie]# cat ping.sh#!/bin/bash# filename: /home/dbatlbb/script/liweiwie/ping.shfor 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 ....." fidone[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]#