Log Monitoring with Tail – How to Continuously Monitor Logs with Tail That Are Occasionally Rotated

linuxlog-fileslogrotatemonitoringtail

We're using tail to continuously monitor several logs, but when a log is rotated the tail for that file will cease.

As far as I understand, the problem is that when the log is rotated, there is a new file created, and the running tail process doesn't know anything about that new file handle.

Best Answer

Ah, there's a flag for this.

instead of using tail -f /var/log/file we should be using tail -F /var/log/file


tail -F translates to tail --follow=name --retry as in;

  • --follow=name: follow the name of the file instead of the file descriptor
  • --retry: if the file is inaccessible, try again later instead of dying