コマンドの組み合わせを一行丸ごとコピーして、いつでも利用できるようにしておくと非常に便利です。そこで、日常で使われそうな便利なコマンドを時折紹介していきたいと思います。今日はその初投稿です。
インフラエンジニアはメンテナンスやテスト中よくpingを使って疎通確認をすることが多々あります。そして、何秒間通信が途絶えたかなど後から確認することがありますが、素のpingコマンドだけでは以下のように何時に通信が途絶えたかわかりません。
$ ping localhost PING localhost (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.045 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.062 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.084 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.074 ms 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.072 ms
そこで紹介するのが以下のコマンドの組み合わせです。これはpingに日付をつけることができます。メンテナンスやテストの後に時間を報告することがよくありますので、念のためこのコマンドで実行しておくと、後から見返せるのでとても便利です。
$ ping localhost | xargs -I_ date +'%c _' 木 5/28 01:01:25 2020 PING localhost (127.0.0.1): 56 data bytes 木 5/28 01:01:25 2020 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.034 ms 木 5/28 01:01:26 2020 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.102 ms 木 5/28 01:01:27 2020 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.083 ms 木 5/28 01:01:28 2020 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.072 ms 木 5/28 01:01:29 2020 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.086 ms
以上です!皆さんも是非使ってみてください!