shell scripting batch Ping IP

Server always once bought a lot of ip segment. By late binding, do not know whether these ip binding is successful, so I wrote a shell script, the good lose ip, batch ping about to see is not able to ping.

Script is as follows:

 

 

 

In addition. There is also a ip file, which put all ip called allip

 


Let's run it, look at the results:

 

 


In addition to 8.8.% Of his show ping else fails. These are indeed ip ping nowhere. All right. Effect on these, we look at his principles

First posted about the program:

 

#! /bin/bash
for i in `cat allip`
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
if [ $ping -eq 100  ];then
echo ping $i fail
else
echo ping $i ok
fi
done

The procedure is simple, now one by one to explain

 

#! /bin/bash

for i in `cat allip`  #这个是逐个读取allip文件里的ip
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
#上面一行是对读出来的ip ping一次,看是否ping通。并取出loss的百分比的值 也就是掉包的值 ,看是否掉包
if [ $ping -eq 100  ];then #比较一下,看掉包的值是不是100,如果是100就是全部掉包,那就是没ping通,那就显示 ping ip fail,如果不等于100的话,就ping通了,就显示 Ping ip OK
echo ping $i fail
else
echo ping $i ok
fi
done

 

结束,小工具挺有用的,有时那么多的ip,一次性就ping完了。

Guess you like

Origin www.cnblogs.com/shawhe/p/11072067.html