みなさん!実行するコマンドの結果に時刻がつくととても便利と思いませんか?
たとえばpingやvmstat等のコマンドを実行すると時刻が通常はつかないため
いつ時点の結果化わからないということはないでしょうか。
awkコマンドを使用して出力された結果に時刻をつけることができるので
この対応をしてみてはいかがでしょうか。
| awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
をつけるだけでその対応ができます!それに実行するコマンドはなんでもOKになります。
以下は対応例です。
■pingの場合
<通常の場合>
$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
<時刻を付けた場合>
$ ping localhost | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/01/01 19:00:09 PING localhost (127.0.0.1) 56(84) bytes of data.
2015/01/01 19:00:09 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.018 ms
2015/01/01 19:00:10 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.026 ms
2015/01/01 19:00:11 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.030 ms
2015/01/01 19:00:12 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
2015/01/01 19:00:13 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.020 ms
■vmstatの場合
<通常の場合>
$ vmstat 1 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 150708 148540 3346224 0 0 8 66 1 1 0 0 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 66 75 0 1 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 41 48 0 0 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 45 50 0 0 100 0 0
<時刻を付けた場合>
$ vmstat 1 10 | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/01/01 19:00:29 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
2015/01/01 19:00:29 r b swpd free buff cache si so bi bo in cs us sy id wa st
2015/01/01 19:00:29 2 0 0 150708 148540 3346204 0 0 8 66 1 1 0 0 100 0 0
2015/01/01 19:00:30 0 0 0 150692 148540 3346204 0 0 0 0 65 66 0 0 100 0 0
2015/01/01 19:00:31 0 0 0 150692 148540 3346208 0 0 0 0 64 73 0 0 100 0 0
これでログを取れば、いつ時点か分かるのでかなり重宝しますよ!
たとえばpingやvmstat等のコマンドを実行すると時刻が通常はつかないため
いつ時点の結果化わからないということはないでしょうか。
awkコマンドを使用して出力された結果に時刻をつけることができるので
この対応をしてみてはいかがでしょうか。
| awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
をつけるだけでその対応ができます!それに実行するコマンドはなんでもOKになります。
以下は対応例です。
■pingの場合
<通常の場合>
$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
<時刻を付けた場合>
$ ping localhost | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/01/01 19:00:09 PING localhost (127.0.0.1) 56(84) bytes of data.
2015/01/01 19:00:09 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.018 ms
2015/01/01 19:00:10 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.026 ms
2015/01/01 19:00:11 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.030 ms
2015/01/01 19:00:12 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
2015/01/01 19:00:13 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.020 ms
■vmstatの場合
<通常の場合>
$ vmstat 1 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 150708 148540 3346224 0 0 8 66 1 1 0 0 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 66 75 0 1 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 41 48 0 0 100 0 0
0 0 0 150700 148540 3346232 0 0 0 0 45 50 0 0 100 0 0
<時刻を付けた場合>
$ vmstat 1 10 | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0}'
2015/01/01 19:00:29 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
2015/01/01 19:00:29 r b swpd free buff cache si so bi bo in cs us sy id wa st
2015/01/01 19:00:29 2 0 0 150708 148540 3346204 0 0 8 66 1 1 0 0 100 0 0
2015/01/01 19:00:30 0 0 0 150692 148540 3346204 0 0 0 0 65 66 0 0 100 0 0
2015/01/01 19:00:31 0 0 0 150692 148540 3346208 0 0 0 0 64 73 0 0 100 0 0
これでログを取れば、いつ時点か分かるのでかなり重宝しますよ!