shell脚本--批量测试主机连通性ping IP
-
vi target_ip.txt
新建文本文件,保存要连接的IP地址137.32.117.53 137.32.117.60 137.32.117.64
-
vi ping.sh
新建shell文件#!/bin/bash # filename: /tmp/mydir/target_ip.txt for ips in `cat /tmp/mydir/target_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
-
chmod 755 ping.sh
修改为可执行文件