Delete files with logrotate
Is it possible JUST to delete the log files in a directory by using logrotate w/o actually rotating them? We have an app that generates logs in the following format: app.log.DD_MM_YYYY. I am unsuccessful with logrotate having the following config:
/opt/log/app/app.log.* {
rotate 0
missingok
nomail
}
Can log rotate do this or should I just write a script and place it within cron?
Best, -Iulian
In that case you may want to use postrotate. In the example below postrotate will delete files that are older that 1 day after logs been rotated, feel free to modify it to fit your needs.
/opt/log/app/app.log.* {
missingok
nomail
postrotate
/usr/bin/find /opt/log/app/ -name "app.log.*" -type f -mtime +0 -exec rm {} \;
endscript
}
The purpose of logrotate is to keep a custom number of log files on a custom time interval. I would use cron for your task. More about what you can do with logrotate here: http://www.jamescoyle.net/cheat-sheets/676-logrotate-cheat-sheet