shell循环ping ip的写法

#!/bin/bash
 for i in `seq 1 20`
  do
 if ping -w 2 -c 1 192.168.43.$i | grep "100%" > /dev/null;then
  echo "192.168.43.$i is not reachable"
  else
 echo "192.168.43.$i is reachable"
 fi
  done

  

-w 2 表示等待时间为2秒。-c 1表示ping 1次

[root@centos6 ~]# ./ping.sh
192.168.43.1 is not reachable
192.168.43.2 is reachable
192.168.43.3 is not reachable
192.168.43.4 is not reachable
192.168.43.5 is not reachable

  

作者:tigergao
功不唐捐 玉汝于成
原文地址:https://www.cnblogs.com/tigergaonotes/p/14175752.html