我的博客已迁移到xdoujiang.com请去那边和我交流
cat ip.sh
#!/bin/bash
#--------------------------------------------------
#Author:jimmygong
#Email:jimmygong@taomee.com
#FileName:ip.sh
#Function:
#Version:1.0
#Created:2015-11-02
#--------------------------------------------------
set -o nounset
ipfile="/root/iplist"
[[ -e $ipfile ]] || exit 1
pingdir="/opt/$(date +%Y%m%d)"
pinglog=${pingdir}/ping
pinglog2=${pingdir}/$(date +%s)ping
function pingfc ()
{
[[ -d ${pingdir} ]] || mkdir -p ${pingdir}
[[ -e $pinglog ]] && `> $pinglog`
[[ ! -e $pinglog ]] && touch $pinglog
i=1
while read ipline
do
(
packet=`ping -s 100 -c 100 -q $ipline|awk /transmitted/|awk '{print $6}'`
echo "$ipline $packet" >> $pinglog
)&
[[ $i%10 -eq 0 ]] && wait
done < $ipfile
wait
cat $pinglog|sort -rnk2 -t " " > $pinglog2 2>&1
}
function main ()
{
while true
do
pingfc
sleep 60
done
}
main
exit 0
==================================说明============================================
bash ip.sh
执行结果
cat ping.log
111.111.111.111 100%
222.222.222.222 100%
333.333.333.333 23%
444.444.444.444 18%
555.555.555.555 17%
666.666.666.666 14%
777.777.777.777 13%
888.888.888.888 13%
999.999.999.999 12%
cat iplist.txt
111.111.111.111
222.222.222.222
333.333.333.333
444.444.444.444
555.555.555.555
666.666.666.666
777.777.777.777
888.888.888.888
999.999.999.999
-s 字节数指定发送的数据字节数预设值是56加上8字节的ICMP头一共是64ICMP数据字节。
Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
-c 数目在发送指定数目的包后停止。
-c count
Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.
-q 不显示任何传送封包的信息只显示最后的结果。
-q Quiet output. Nothing is displayed except the summary lines at startup time and when finished.
二、需要安装fping命令(apt-get -y install fping --force-yes或yum -y install fping)
fping - sends ICMP ECHO_REQUEST packets to network hosts
fping -ef /root/iplist.txt >ping.log 2>&1
==================================说明============================================
执行结果
cat ping.log
10.1.1.101 is alive (0.66 ms)
10.1.1.102 is alive (1.22 ms)
10.1.1.104 is alive (1.28 ms)
10.1.1.105 is alive (1.26 ms)
10.1.1.103 is unreachable
cat iplist.txt
10.1.1.101
10.1.1.102
10.1.1.103
10.1.1.104
10.1.1.105
-f Read list of targets from a file.
-e Show elapsed (round-trip) time of packets
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com