1

I am rotating my logs using logrotate in linux. I want to remove my logs older than 7 days. So I tried maxage option in logrotate but it is not working as expected.

Let say I have 6 logs which is created in the order shown below

Date            filename

18th oct    sample.log.2017-10-18
17th oct    sample.log.2017-10-17
16th oct    sample.log.2017-10-16
15th oct    sample.log.2017-10-15
14th oct    sample.log.2017-10-14
13th oct    sample.log.2017-10-13
12th oct    sample.log.2017-10-12

Today(19th oct) no sample log is created so no log is rotated and also sample.log.2017-10-12 needs to be deleted but it is not deleted why?

find logrotate property file below

/var/log/test/*.log {

    missingok
    notifempty
    nocompress
    daily
    dateext
    dateformat .%Y-%m-%d
    maxage 7

}
  • According to the man pages for log rotate, "maxage count - Remove rotated logs older than <count> days. The age is only checked if the logfile is to be rotated." Since there was no rotation, there no check – Raman Sailopal Oct 19 '17 at 11:47
  • @RamanSailopal. okay. so is there any way we can achieve this without rotation – wazza Oct 19 '17 at 12:03
  • Use the find command with -ctime/mtime and -delete – Raman Sailopal Oct 19 '17 at 12:06
  • @RamanSailopal if i include that in post rotate same will happen right if there is no rotation – wazza Oct 19 '17 at 12:13
  • You will need to run the find and delete of another process, maybe off a daily cron job. – Raman Sailopal Oct 19 '17 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.