ping一堆机器的二种方法(shell或fping)

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
我的博客已迁移到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









本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1639753,如需转载请自行联系原作者
目录
相关文章
|
存储 Unix Shell
确定Shell脚本在操作系统中的具体位置方法。
这对于掌握Linux的文件系统组织结构和路径方面的理解很有帮助,是我们日常工作和学习中都可能使用到的知识。以上讲解详细清晰,应用简便,是每一个想要精通操作系统的计算机爱好者必备的实用技能。
690 17
|
Shell Linux 测试技术
6种方法打造出色的Shell脚本
6种方法打造出色的Shell脚本
6种方法打造出色的Shell脚本
|
弹性计算 安全 Linux
阿里云国际版使用ping命令测试ECS云服务器不通的排查方法
阿里云国际版使用ping命令测试ECS云服务器不通的排查方法
|
域名解析 弹性计算 安全
无法ping通ECS服务器公网IP的排查方法
无法ping通ECS服务器公网IP的排查方法
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
289 5
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
281 3
|
Ubuntu Shell Linux
linux shell 后台执行脚本的方法 脚本后台运行 后台运行程
linux shell 后台执行脚本的方法 脚本后台运行 后台运行程
1289 0
|
监控 Shell
生产环境Shell脚本Ping监控主机是否存活(多种方法)
生产环境Shell脚本Ping监控主机是否存活(多种方法)
|
运维 Shell
Shell脚本判断IP是否合法性(多种方法)
Shell脚本判断IP是否合法性(多种方法)
|
监控 Shell
Shell脚本Ping监控主机是否存活并发邮件报警(三种方法)
Shell脚本Ping监控主机是否存活并发邮件报警(三种方法)