I have a simple script which outputs a bunch of logs to screen and I piped the STDOUT to a file to store the logs. Since this script is long running, I needed to rotate the log files so they are chucked into smaller more manageable ones.
The problem I faced was that once the logrotate
moves the current log file into a new one, the newly created log file is not populated with the logs anymore. It seems that the once the original log file is removed, its file handler is lost and redirection won't work anymore.
I also found this post which had the same problem as me and claims that it can be fixed by using >>
instead of >
to redirect the output. I tested his solution but it didn't work for me. Does anyone have any idea how to keep the redirection work?