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 修改为可执行文件

posted @ 2019-03-28 12:12  人间丶迷走  阅读(3505)  评论(0编辑  收藏  举报