码迷,mamicode.com
首页 > 系统相关 > 详细

shell 编写脚本批量ping ip

时间:2016-08-11 23:00:30      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:shell脚本   批量ping   

最近做机房带宽检测。最近编写一个shell脚本批量ping各地机房的ip,返回失败率及平均响应时间

#!/bin/bash
log=$1.log
echo -n "" > $log
for i in `cat $1`
do
  /bin/ping -s 1000 -f -c 100  $i > ip.txt
echo "`curl ip.cn?ip=$i`  `cat ip.txt | grep transmitted  | gawk ‘{print $6}‘`  `cat ip.txt | grep avg  | gawk -F / ‘{print $5}‘`" >> $log
done
rm -rf ip.txt

把所有需要检测的IP存放在文本文件1中

执行脚本 sh ip.sh 1

执行脚本后会生成一个文件:1.log  

cat 1.log 

IP:122.114.78.23 来自:河南省郑州市 景安网络  0%  48.073

本文出自 “宁静致远” 博客,请务必保留此出处http://irow10.blog.51cto.com/2425361/1837024

shell 编写脚本批量ping ip

标签:shell脚本   批量ping   

原文地址:http://irow10.blog.51cto.com/2425361/1837024

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!