LoginSignup
2
0

More than 3 years have passed since last update.

awkを使ってvmstatに日時をつける

Last updated at Posted at 2019-06-13

awkを使えばvmstatだけではなくなんにでも日時をつけることが出来ます。

vmstatに日時をつける

vmstat 1|awk '{print strftime("%Y/%m/%d %H:%M:%S",systime()) " " $0 }'
2019/06/13 09:27:35 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
2019/06/13 09:27:35  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2019/06/13 09:27:35  2  0      0 265972  12900 233000    0    0   274   163  511  423 15  2 83  0  0    
2019/06/13 09:27:36  0  0      0 296276  12900 233116    0    0     0  5072  593 2685 31  3 66  0  0    
2019/06/13 09:27:37  0  0      0 296160  12900 233296    0    0     0     0  397  300 14  0 86  0  0    
2019/06/13 09:27:38  0  0      0 296160  12908 233484    0    0     0    28  428  329 14  0 85  0  1    
2019/06/13 09:27:39  0  0      0 296036  12908 233704    0    0     0     0  488  393 14  1 85  0  0    
2019/06/13 09:27:40  0  0      0 295788  12908 233932    0    0     0     0  465  343 14  0 86  0  0    
2019/06/13 09:27:41  1  0      0 295540  12908 234148    0    0     0     0  424  311 13  2 85  0  0    
2019/06/13 09:27:42  0  0      0 295292  12908 234348    0    0     0     0  431  310 14  1 85  0  0    
2019/06/13 09:27:43  0  0      0 295168  12916 234492    0    0     0    12  431  325 13  1 86  0  0    

tail -f したデータに日時をつける

tail -f access_log | awk '{print strftime("%Y/%m/%d %H:%M:%S",systime()) " " $0 }'
2019/06/13 09:31:14 1.2.3.4 - - [13/Jun/2019:09:09:08 +0000] "GET / HTTP/1.1" 200 479 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0 Waterfox/56.2.10"
2019/06/13 09:31:14 1.2.3.4 - - [13/Jun/2019:09:09:08 +0000] "GET /css/demo.css HTTP/1.1" 304 - " "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0 Waterfox/56.2.10"
2019/06/13 09:31:14 1.2.3.4 - - [13/Jun/2019:09:09:08 +0000] "GET /js/jquery.min.js HTTP/1.1" 304 - "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0 Waterfox/56.2.10"

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0