如何为每个ping结果加时间戳? [英] How do I timestamp every ping result?

查看:1698
本文介绍了如何为每个ping结果加时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ping 默认返回以下值:

64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms

有什么办法可以添加时间戳吗?

Is there some way I can get it to add the timestamp?

例如,

Mon 21 May 2012 15:15:37 EST | 64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms

我正在使用OS X&v10.7(Lion),它似乎有一些 BSD a> ping版本.

I'm on OS X v10.7 (Lion) which seems to have some BSD version of ping.

推荐答案

由于某种原因,我无法将基于Perl的解决方案重定向到文件,因此我不断搜索并找到了bash唯一的方法:

I could not redirect the Perl based solution to a file for some reason so I kept searching and found a bash only way to do this:

ping www.google.fr | while read pong; do echo "$(date): $pong"; done

Wed Jun 26 13:09:23 CEST 2013: PING www.google.fr (173.194.40.56) 56(84) bytes of data.
Wed Jun 26 13:09:23 CEST 2013: 64 bytes from zrh04s05-in-f24.1e100.net (173.194.40.56): icmp_req=1 ttl=57 time=7.26 ms
Wed Jun 26 13:09:24 CEST 2013: 64 bytes from zrh04s05-in-f24.1e100.net (173.194.40.56): icmp_req=2 ttl=57 time=8.14 ms

功劳归于 https://askubuntu.com/a/137246

这篇关于如何为每个ping结果加时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆