I am trying to configure logrotate in RHEL for tomcat6 logs. Currently, logrotate works fine for catalina.out log, it is rotated and compressed properly.
The problem
I spent a quite a while reading a lot of documentation. Logrotate does not seem to be able to group the different files with dates included in the name of the file. Logrotate can not do what we need it to do.
You have two options change the logging facility provided by java / tomcat to not include the date in the file name. http://tomcat.apache.org/tomcat-6.0-doc/logging.html
The second and quicker way is to use your own little script to do the work for you, using find. https://serverfault.com/questions/256218/logrotation-when-filenames-includes-date, https://serverfault.com/a/256231/71120
find /pathtologs/* -mtime +5 -exec rm {} \;
I went with the second option, because our developers have coded for dates in the files names. So it needs to stay that way.
The -mtime +5 sets find to only look for files who are older then 5 days.
From find's documentation.
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
Updated as per comment
find /pathtologs/* -mtime +5 -delete
If you specifically want to delete, this is a quick way to do it.
If you need to some other command you can always replace the exec rm {} \; with something else.