Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

linux - Logrotate not deleting file after certain days

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

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

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...