tech note

インフラ技術や車についてつぶやいていくブログ

bash上でコマンド出力結果に日時を入れる

f:id:tea_cat:20180913013643j:plain

nice vmstat 1 | nice awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
)
# nice vmstat 1 | nice awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/07/24 11:26:46 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
2015/07/24 11:26:46  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2015/07/24 11:26:46  1  0      0 282540 151856 297024    0    0     0     2    4    5  0  0 100  0  0
2015/07/24 11:26:47  0  0      0 282540 151856 297024    0    0     0    40   56   54  0  0 100  0  0
2015/07/24 11:26:48  0  0      0 282540 151856 297024    0    0     0    24   35   51  0  0 100  0  0
2015/07/24 11:26:49  0  0      0 282540 151856 297024    0    0     0     0   39   41  0  0 100  0  0
2015/07/24 11:26:50  0  0      0 282540 151856 297024    0    0     0     0   28   41  0  0 100  0  0
2015/07/24 11:26:51  0  0      0 282540 151856 297024    0    0     0     0   29   39  0  0 100  0  0
2015/07/24 11:26:52  0  0      0 282540 151856 297024    0    0     0     0   28   42  0  0 100  0  0
2015/07/24 11:26:53  0  0      0 282540 151856 297024    0    0     0     0   31   42  0  0 100  0  0
2015/07/24 11:26:54  0  0      0 282540 151856 297024    0    0     0     0   38   39  0  0 100  0  0
2015/07/24 11:26:55  0  0      0 282540 151856 297024    0    0     0     0   42   43  0  0 100  0  0
^C

例)
# ping 8.8.8.8 | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/07/24 11:27:20 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
2015/07/24 11:27:20 64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=1.16 ms
2015/07/24 11:27:21 64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=1.42 ms
2015/07/24 11:27:22 64 bytes from 8.8.8.8: icmp_seq=3 ttl=56 time=1.22 ms
2015/07/24 11:27:23 64 bytes from 8.8.8.8: icmp_seq=4 ttl=56 time=1.26 ms
2015/07/24 11:27:24 64 bytes from 8.8.8.8: icmp_seq=5 ttl=56 time=1.16 ms
2015/07/24 11:27:25 64 bytes from 8.8.8.8: icmp_seq=6 ttl=56 time=1.11 ms
2015/07/24 11:27:26 64 bytes from 8.8.8.8: icmp_seq=7 ttl=56 time=1.18 ms
2015/07/24 11:27:27 64 bytes from 8.8.8.8: icmp_seq=8 ttl=56 time=1.12 ms
2015/07/24 11:27:28 64 bytes from 8.8.8.8: icmp_seq=9 ttl=56 time=1.13 ms
2015/07/24 11:27:29 64 bytes from 8.8.8.8: icmp_seq=10 ttl=56 time=1.10 ms
^C