LoginSignup
1
2

今回はtailコマンドを使用してリアルタイムにログを確認する方法を解説致します。

リアルタイムで確認するには?

tailコマンドの「-f」オプションを使用する事でログ等のファイルをリアルタイムで確認する事が出来ます。

動作確認を行う際にリアルタイムに反応を確認できる為、非常に便利なオプションとなっております。

下記コマンド例となります。

tail -f ファイルパス

メールログをリアルタイムで確認する

先程解説したコマンドを使用しメールログをリアルタイムで確認してみます。

下記コマンドとなります。

tail -f /var/log/maillog
Jun 17 12:34:56 mailserver postfix/smtpd[12345]: connect from example.com[192.168.1.1]
Jun 17 12:34:57 mailserver postfix/smtpd[12345]: 3F1E12ABCD: client=example.com[192.168.1.1]
Jun 17 12:34:57 mailserver postfix/cleanup[12346]: 3F1E12ABCD: message-id=<1234567890@example.com>
Jun 17 12:34:58 mailserver postfix/qmgr[12347]: 3F1E12ABCD: from=<sender@example.com>, size=1234, nrcpt=1 (queue active)
Jun 17 12:34:59 mailserver postfix/smtpd[12345]: disconnect from example.com[192.168.1.1] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Jun 17 12:35:00 mailserver postfix/local[12348]: 3F1E12ABCD: to=<recipient@example.com>, relay=local, delay=4, delays=2/0/0/2, dsn=2.0.0, status=sent (delivered to mailbox)

※上記は例となります。値に意味はありません。

検索条件を追加してみる

先程のtailコマンドにgrepを使用する事で条件に絞った出力を行う事が出来ます。

下記例となります。

tail -f /var/log/maillog |grep "status="

今回はstatusのみを確認できるように指定しました。

Jun 17 12:34:58 mailserver postfix/qmgr[12347]: 3F1E12ABCD: from=<sender@example.com>, size=1234, nrcpt=1 (queue active)
Jun 17 12:35:00 mailserver postfix/local[12348]: 3F1E12ABCD: to=<recipient@example.com>, relay=local, delay=4, delays=2/0/0/2, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 17 12:36:02 mailserver postfix/smtp[12349]: 4G2H34EFGH: to=<another@example.com>, relay=smtp.example.com[192.168.1.2]:25, delay=3, delays=1/0.5/1.5/0, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 9C1D12ABCD)
Jun 17 12:37:05 mailserver postfix/qmgr[12347]: 5I3J45IKLM: from=<noreply@example.com>, size=5678, nrcpt=1 (queue active)
Jun 17 12:37:07 mailserver postfix/local[12348]: 5I3J45IKLM: to=<user@example.com>, relay=local, delay=5, delays=3/0.5/1/0.5, dsn=2.0.0, status=sent (delivered to mailbox)
1
2
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
1
2