I would like to do the following to monitor for a pattern in a log file:
tail -f ./app.log | grep "My Pattern: .*" >> ./MyPattern.txt &
This is working fine until the app.log
reaches 500MB and it is moved to be app-2015-10-28.0.log
and a new app.log
is created. When this happens the tail -f
will stop working. Stopping and running the same command again will work, but in between stopping and starting, the pattern that appears in between the restarting may be missed.
Another condition of rolling is when it is 00:00. The same rolling will happen even when the log is < 500MB.
Log rolling is done at application level and we cannot control that part.
How can we detect the log has been rolled, without missing the patterns of interest?
tail -F
ortail --follow=name
will follow the filename rather than the file descriptor. – Mark Wagner Oct 27 '15 at 22:35