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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM