Linux下ping加上时间戳

时间:2021-08-23 03:35:29

命令(ping10次):

ping 192.168.5.160 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '

 

调用awk中的时间处理函数strftime给每个测量值加上时间戳。
结果如下:

PING 192.168.5.160 (192.168.5.160) 56(84) bytes of data.        15:51:38
64 bytes from 192.168.5.160: icmp_seq=1 ttl=64 time=0.245 ms        15:51:38
64 bytes from 192.168.5.160: icmp_seq=2 ttl=64 time=0.192 ms        15:51:39
64 bytes from 192.168.5.160: icmp_seq=3 ttl=64 time=0.190 ms        15:51:40
64 bytes from 192.168.5.160: icmp_seq=4 ttl=64 time=0.215 ms        15:51:41
64 bytes from 192.168.5.160: icmp_seq=5 ttl=64 time=0.214 ms        15:51:42
64 bytes from 192.168.5.160: icmp_seq=6 ttl=64 time=0.213 ms        15:51:43
64 bytes from 192.168.5.160: icmp_seq=7 ttl=64 time=0.209 ms        15:51:44
64 bytes from 192.168.5.160: icmp_seq=8 ttl=64 time=0.209 ms        15:51:45
64 bytes from 192.168.5.160: icmp_seq=9 ttl=64 time=0.206 ms        15:51:46
64 bytes from 192.168.5.160: icmp_seq=10 ttl=64 time=0.204 ms        15:51:47
        15:51:47
--- 192.168.5.160 ping statistics ---        15:51:47
10 packets transmitted, 10 received, 0% packet loss, time 8997ms        15:51:47
rtt min/avg/max/mdev = 0.190/0.209/0.245/0.022 ms        15:51:47