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 ?

0

1 Answer 1

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.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.