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

  

posted @ 2020-12-22 22:12  tigergaonotes  阅读(1599)  评论(0编辑  收藏  举报