Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I have this logrotate config file. I want to delete files that older than 2 days. After the first day, it add .1 to the filename of all the files that older than 2 days instead of deleting those files Then after the second day, still not deleting those file. I am not sure where I did wrong. But it works if I force run it logrotate -f '/etc/logrotate.d/configname'

Here's the config file I created

/data/adrouters/*/IAV/*/* /data/adrouters/*/logs/* /data/adrouters/*/SchOutIav/*/* /data/adrouters/*/SiteInfo/archive/* /data/logs/* {
    missingok
    rotate 1
    nocreate
    nodateext
    ifempty
    lastaction
        find /data/adrouters/ -type f -mtime +2 -exec rm {} ;
        find /data/logs/ -type f -mtime +2 -exec rm {} ;
    endscript
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

logrotate config file only specify the rules logrotate applies when running against the logfiles you specified.

You also need to add your logrotate execution line to your cronjob.

Adding cronjob as root(cronjob is based on different user!):

sudo su
crontab -e # <==== this will open an editor for you to edit your cronjobs, for root user

In the editor, you add an entry like this:

*/5 * * * * logrotate '/etc/logrotate.d/configname'

The "*/5 * * * " part is cron expression, it means executes every 5minutes, you need to change this to something make sense for you. In testing things out, you can set it to "/1 * * * *" and you can monitor on cron's log to see it actually happens.

Resource for cron: https://crontab.guru/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...