If you don't want to use find
inside postrotate
, no, you can't.
logrotate
treats every instance of server.log
rotated by Tomcat/JBoss as a different file, and since they are unique, logrotate
will rotate them only once. maxage
- the directive that removes rotated logs older than n
days - is only checked if the logfile is to be rotated, so that maxage
is only executed once and can't keep track of the file's age.
However, if you change your mind about using find
, logrotate
can help you simplify the management of log files created by Tomcat and JBoss. I use it to compress and remove old files with a configuration file like this:
/path/to/logs/server.log.????-??-?? {
compress
compresscmd /usr/bin/bzip2
nocreate
nodateext
ifempty
missingok
rotate 1
size 0
start 0
lastaction
# Remove rotated files older than 180 days
find /path/to/logs -name 'server.log.????-??-??.0.bz2' -mtime +180 -exec rm {} \;
endscript
}
where:
rotate 1
and compress
rename and compress, say, server.log.20131201
to server.log.20131201.0.bz2
. The 0
between the timestamp and the .bz2
extension comes from start 0
.
size 0
makes sure that files are always renamed and compressed.
- The
lastaction
block removes rotated files older than 180 days.