18

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

user9517
  • 115,471
  • 20
  • 215
  • 297
Iulian
  • 428
  • 1
  • 3
  • 8
  • If you dont need those logs why not disable logging feature on your app? – Deeh Jul 31 '15 at 18:30
  • 3
    I am sorry but I can't count that as an answer Deeh. To feed your curiosity, we need those logs for different operations like debugging, we just don't want to keep them there to rot. – Iulian Aug 04 '15 at 10:00

2 Answers2

27

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
}
Deeh
  • 581
  • 3
  • 9
4

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

Alex
  • 340
  • 3
  • 8
  • 2
    Please do not post link-only answers to prevent link rot. Instead, add the most relevant information from the link to your answer or alternatively, post the link as a comment instead of an answer. See [this](http://serverfault.com/help/how-to-answer) help center article for further information. – Sven Jul 24 '15 at 20:13