[root@test ~]# ping 192.168.2.1 -c 10 
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.638 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.341 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.291 ms
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.259 ms
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.338 ms
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.339 ms
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=0.243 ms
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.234 ms
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.333 ms
64 bytes from 192.168.2.1: icmp_seq=10 ttl=64 time=0.284 ms

--- 192.168.2.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9002ms
rtt min/avg/max/mdev = 0.234/0.330/0.638/0.109 ms
上面我们ping了10次,每次的时间1秒,因此比如你要ping连天那么就是60*60*24*2=172800。
接下来是加时间戳:
root@test ~]# ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.    10:30:21
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.436 ms    10:30:21
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.343 ms    10:30:22
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.368 ms    10:30:23
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.280 ms    10:30:24
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.308 ms    10:30:25
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.360 ms    10:30:26
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=0.319 ms    10:30:27
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.274 ms    10:30:28
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.360 ms    10:30:29
64 bytes from 192.168.2.1: icmp_seq=10 ttl=64 time=0.265 ms    10:30:30
    10:30:30
--- 192.168.2.1 ping statistics ---    10:30:30
10 packets transmitted, 10 received, 0% packet loss, time 9000ms    10:30:30
rtt min/avg/max/mdev = 0.265/0.331/0.436/0.052 ms    10:30:30
然后我们把信息输出到文本:
[root@test ~]# ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '>ping.log
[root@test ~]# cat ping.log
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.    10:37:23
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.398 ms    10:37:23
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.288 ms    10:37:24
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.465 ms    10:37:25
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.310 ms    10:37:26
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.275 ms    10:37:27
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.247 ms    10:37:28
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=0.339 ms    10:37:29
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.270 ms    10:37:30
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.297 ms    10:37:31
64 bytes from 192.168.2.1: icmp_seq=10 ttl=64 time=0.289 ms    10:37:32
    10:37:32
--- 192.168.2.1 ping statistics ---    10:37:32
10 packets transmitted, 10 received, 0% packet loss, time 9000ms    10:37:32
rtt min/avg/max/mdev = 0.247/0.317/0.465/0.067 ms    10:37:32
最后,我们需要把任务放到后台去:
[root@test ~]# nohup ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '>ping1.log &
[1] 2616
[root@test ~]# ls
anaconda-ks.cfg  check1.sh  Desktop  eygle.com  httpd  login  pass.conf  ping1.log  ping.log  test1.sh  test1.sh1
[root@test ~]# cat ping1.log 
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.    10:40:22
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.373 ms    10:40:22
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.343 ms    10:40:23
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.335 ms    10:40:24
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.299 ms    10:40:25
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.372 ms    10:40:26
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.236 ms    10:40:27
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=0.394 ms    10:40:28
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.317 ms    10:40:29
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.490 ms    10:40:30
64 bytes from 192.168.2.1: icmp_seq=10 ttl=64 time=1.65 ms    10:40:31
    10:40:31
--- 192.168.2.1 ping statistics ---    10:40:31
10 packets transmitted, 10 received, 0% packet loss, time 9001ms    10:40:31
rtt min/avg/max/mdev = 0.236/0.480/1.650/0.395 ms    10:40:31

-The End-

原文:http://www.enkj.com/help/newscontent/107717

最新文章

  1. 如何快速上手使用STM32库函数
  2. eclipse中jre system library ,web app libraries,referenced libraries,user libraries
  3. e.Handled的理解
  4. c/c++:动态库 静态库 linux/windows 例子 (转)
  5. UESTC 1237 质因子分解
  6. unix/linux进程详解
  7. Silic PHP大马Cookie欺骗漏洞
  8. 布局转换:文档流->绝对定位
  9. C#.ToString()格式大全
  10. (function(){})(jQuery)的功能和用途?
  11. Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect
  12. tar.gz文件命名和压缩解压方法
  13. 面试题-Java Web-JSP部分
  14. 一些Wifi破解姿势
  15. expressjs 支持umeditor 的图片上传
  16. 轻量级弹出框 lightbox
  17. 《深入理解Java虚拟机》——Java内存区域与内存溢出异常
  18. 【k短路&A*算法】BZOJ1975: [Sdoi2010]魔法猪学院
  19. NodeJs连接操作MongoDB数据库
  20. new关键字创建对象带不带{}的区别

热门文章

  1. Label设置行间距--b
  2. constant属性详解
  3. Xcode中使用GitHub详解
  4. Asterix and Obelix
  5. windows下NGINX和PHP配合(FASTCGI)
  6. [LeetCode#159] Missing Ranges Strobogrammatic Number
  7. Myeclipse 保存jsp异常Save FailedCompilation unit name must end with .java, or one of the registered Java-like extensions
  8. 【转】[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
  9. 模糊化GPU滤镜汇总
  10. apply和call详解