55
18
I have a Linux program which can write information to stdout and stderr.
I have a shell script which redirects that output to a file in /var/log
. (Via >>
and 2>&1
.)
Is there a way to make that log file rotate? (max size, then switch to a different file, keep only a limited number of files)
I've seen a few answers which talk about the logrotate
program, which sounds good, but they also seem to be focused on programs which are generating log files internally and handle HUP signals. Is there a way to make this work with a basic output redirection script?
1Why can't you just modify the script that redirects the output to contain the logic for the rotation? – MaQleod – 2011-06-01T05:05:40.537
I could, if someone could tell me how to detect the size of a logfile and rotate it out from under the stdout of a process without disturbing that process. I don't have to use
logrotate
if there's a better option, that just sounded like a convenient starting point for discussion. – Miral – 2011-06-01T05:12:39.4502You don't have to use logrotate, but using logrotate just saves time... There is usually little point reinventing the wheel. – bubu – 2011-06-01T05:43:51.097
Exactly my point. So is there a way to make logrotate work with an ongoing process's redirected stdout? – Miral – 2011-06-01T06:12:17.833