logrotate compress files after the postrotate script logrotate compress files after the postrotate script linux linux

logrotate compress files after the postrotate script


Adding this info here in case of anyone else that comes across this thread when actually searching for wanting a way to run a script on a file once compression has completed.

As suggested above using postrotate/endscript is no good for that.

Instead you can use lastaction/endscript, which does the job perfectly.


The postrotate script always runs before compression even when sharedscripts is in effect. Hasturkun's additional response to the first answer is therefore incorrect. When sharedscripts is in effect the only compression performed before the postrotate is for old uncompressed logs left lying around because of a delaycompress. For the current logs, compression is always performed after running the postrotate script.


The postrotate script does run before compression occurs: from the man page for logrotate

The next section of the config files defined how to handle the log file /var/log/messages. The log will go through five weekly rotations before being removed. After the log file has been rotated (but before the old version of the log has been compressed), the command /sbin/killall -HUP syslogd will be executed.

In any case, you can use the delaycompress option to defer compression to the next rotation.