% ping www.jp.freebsd.org
PING www.jp.freebsd.org (211.14.6.244): 56 data bytes
64 bytes from 211.14.6.244: icmp_seq=0 ttl=51 time=17.334 ms
64 bytes from 211.14.6.244: icmp_seq=1 ttl=51 time=16.747 ms
64 bytes from 211.14.6.244: icmp_seq=2 ttl=51 time=17.144 ms
64 bytes from 211.14.6.244: icmp_seq=4 ttl=51 time=14.234 ms
^C
% ping www.google.com | while read line; do echo `date` $line; done
Sun Jan 13 14:19:35 JST 2019 PING www.google.com (172.217.161.68): 56 data bytes
Sun Jan 13 14:19:35 JST 2019 64 bytes from 172.217.161.68: icmp_seq=0 ttl=55 time=1.253 ms
perl で:
% ping www.google.com | perl -ne 'print scalar(localtime), " ", $_'
Sun Jan 13 14:19:58 2019 PING www.google.com (172.217.31.132): 56 data bytes
Sun Jan 13 14:19:58 2019 64 bytes from 172.217.31.132: icmp_seq=0 ttl=55 time=1.614 ms
perl で (書式設定付き):
% ping www.google.com | perl -pe '$|=1;@x=localtime();$x=sprintf("%02d/%02d/%02d %02d:%02d:%02d: ",$x[5]+1900,$x[4]+1,$x[3],$x[2],$x[1],$x[0]); s/^/$x/;'
2019/01/13 14:20:26: PING www.google.com (172.217.26.36): 56 data bytes
2019/01/13 14:20:26: 64 bytes from 172.217.26.36: icmp_seq=0 ttl=55 time=1.486 ms
moreutil に含まれている ts コマンドで:
ping www.google.com | ts
Sun 13 14:20:26: PING www.google.com (172.217.26.36): 56 data bytes
Sun 13 14:20:26: 64 bytes from 172.217.26.36: icmp_seq=0 ttl=55 time=1.486 ms
moreutil に含まれている ts コマンドで (書式設定付き):
% ping www.google.com | ts '%F %T'
2019-01-13 14:20:26: PING www.google.com (172.217.26.36): 56 data bytes
2019-01-13 14:20:26: 64 bytes from 172.217.26.36: icmp_seq=0 ttl=55 time=1.486 ms