bash – 如何为每个ping结果设置时间戳?
发布时间:2020-12-15 16:26:35 所属栏目:安全 来源:网络整理
导读:Ping默认返回: 64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms 有什么方法可以让它添加时间戳? 例如, 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),似乎
Ping默认返回:
64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms 有什么方法可以让它添加时间戳? 例如, 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版本的ping。
如果你的AWK没有strftime():
ping host | perl -nle 'print scalar(localtime)," ",$_' 要将其重定向到文件,请使用标准的shell重定向并关闭输出缓冲: ping host | perl -nle 'BEGIN {$|++} print scalar(localtime),$_' > outputfile 如果要ISO8601格式的时间戳: ping host | perl -nle 'use Time::Piece; BEGIN {$|++} print localtime->datetime,$_' > outputfile (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |