如何时间戳每平的结果? [英] How to timestamp every ping result?
本文介绍了如何时间戳每平的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
平默认返回这样的:
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(狮子),这似乎有一些 BSD版本平
推荐答案
如果您AWK没有的strftime()
:
ping host | perl -nle 'print scalar(localtime), " ", $_'
要重定向到一个文件,使用标准的外壳重定向并关闭输出缓冲:
To redirect it to a file, use standard shell redirection and turn off output buffering:
ping host | perl -nle 'BEGIN {$|++} print scalar(localtime), " ", $_' > outputfile
如果你想为时间戳ISO8601格式为:
If you want ISO8601 format for the timestamp:
ping host | perl -nle 'use Time::Piece; BEGIN {$|++} print localtime->datetime, " ", $_' > outputfile
这篇关于如何时间戳每平的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文