5

I have a script running continuously, reading tail -f /var/log/daemon.log

The problem is, when the file /var/log/daemon.log gets rotated by logrotate, tail still has "file handle" for the old (rotated) file and no longer displays the contents of the new /var/log/daemon.log file

Is there any way to fix this, so that tail shows the contents of the new file, if the file was rotated ?

Martin Vegter
  • 358
  • 75
  • 236
  • 411

1 Answers1

10

Yes. You're looking for tail -F instead of tail -f (that is, a capital F instead of lowercase). Check the tail(1) manpage.

Alternatively, you could use --follow=name --retry, which the man page documents as the same thing.

(These are from GNU coreutils tail. Other tails may not have this; POSIX does not specify -F, --follow, or --retry. If you have to work on those systems, I'd suggest Perl's File::Tail.)

derobert
  • 109,670