Continuing to tail a file after it's been rotated


I use xtail and tail quite a bit to debug problems. Sometimes when I’m up late at night troubleshooting issues, the log rotation jobs will kick off and my tail session will stop updating (tail will follow the file descriptor associated with the file by default, not the name of the file). Since this can make debugging an issue a bit confusing, I’ve made it a habit to alias tail to something like this:

$ alias tailer="tail --follow=name --retry"

The “–follow=name” option will cause tail to follow the name of the file and not the file descriptor, and the “–retry” option will cause tail to try to re-open the file if it’s not accessible (log rotation events will cause the file to change). It’s become second nature to run tailer now, and I don’t get that “WTF?!?” moment at 2am now. ;)

This article was posted by Matty on 2011-03-27 09:08:00 -0400 -0400