Delete files only with logrotate

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have an application which rotates its own log files on an hourly basis. Each hour I want to remove all of the files more then n days old. I have to use logrotate to do this because of business policy.



So what is the logrotate equivalent of running this command every hour?



find /var/log/app -name "*.old" -mtime +1 -exec rm -f ;









share|improve this question























  • -type f also to be sure to delete file and nothing else
    – netmonk
    Sep 15 '15 at 12:51






  • 2




    did you have a look at man logrotate ?
    – Archemar
    Sep 15 '15 at 13:04














up vote
2
down vote

favorite












I have an application which rotates its own log files on an hourly basis. Each hour I want to remove all of the files more then n days old. I have to use logrotate to do this because of business policy.



So what is the logrotate equivalent of running this command every hour?



find /var/log/app -name "*.old" -mtime +1 -exec rm -f ;









share|improve this question























  • -type f also to be sure to delete file and nothing else
    – netmonk
    Sep 15 '15 at 12:51






  • 2




    did you have a look at man logrotate ?
    – Archemar
    Sep 15 '15 at 13:04












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have an application which rotates its own log files on an hourly basis. Each hour I want to remove all of the files more then n days old. I have to use logrotate to do this because of business policy.



So what is the logrotate equivalent of running this command every hour?



find /var/log/app -name "*.old" -mtime +1 -exec rm -f ;









share|improve this question















I have an application which rotates its own log files on an hourly basis. Each hour I want to remove all of the files more then n days old. I have to use logrotate to do this because of business policy.



So what is the logrotate equivalent of running this command every hour?



find /var/log/app -name "*.old" -mtime +1 -exec rm -f ;






logrotate






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 15 '15 at 13:30









Kevdog777

2,087123259




2,087123259










asked Sep 15 '15 at 12:49









user3642765

1314




1314











  • -type f also to be sure to delete file and nothing else
    – netmonk
    Sep 15 '15 at 12:51






  • 2




    did you have a look at man logrotate ?
    – Archemar
    Sep 15 '15 at 13:04
















  • -type f also to be sure to delete file and nothing else
    – netmonk
    Sep 15 '15 at 12:51






  • 2




    did you have a look at man logrotate ?
    – Archemar
    Sep 15 '15 at 13:04















-type f also to be sure to delete file and nothing else
– netmonk
Sep 15 '15 at 12:51




-type f also to be sure to delete file and nothing else
– netmonk
Sep 15 '15 at 12:51




2




2




did you have a look at man logrotate ?
– Archemar
Sep 15 '15 at 13:04




did you have a look at man logrotate ?
– Archemar
Sep 15 '15 at 13:04










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










it's a possibility and you need to test :



cat /etc/logrotate.d/customapp

/var/log/app/*.old
daily
missingok
rotate 0
notifempty



Why rotate 0 ?




If count is 0, old versions are removed rather than rotated. (source : man)







share|improve this answer
















  • 2




    no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
    – keen
    Jun 21 '16 at 20:33

















up vote
0
down vote













logrotate runs once daily and the script can be found here, /etc/cron.daily/logrotate (on CentOS 7). If you want to run it each hour, you first need to move it to /etc/cron.hourly/. Then for the above command the equivalent logrotate script might look like this,



$ cat /etc/logrotate.d/app

/var/log/app/*.old
hourly
rotate 0
firstaction
/usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete
endscript
nocreate
missingok
notifempty






share|improve this answer








New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
    – Scott
    Nov 22 at 5:44










  • If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
    – Tanveer
    Nov 22 at 6:36











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f229807%2fdelete-files-only-with-logrotate%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










it's a possibility and you need to test :



cat /etc/logrotate.d/customapp

/var/log/app/*.old
daily
missingok
rotate 0
notifempty



Why rotate 0 ?




If count is 0, old versions are removed rather than rotated. (source : man)







share|improve this answer
















  • 2




    no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
    – keen
    Jun 21 '16 at 20:33














up vote
1
down vote



accepted










it's a possibility and you need to test :



cat /etc/logrotate.d/customapp

/var/log/app/*.old
daily
missingok
rotate 0
notifempty



Why rotate 0 ?




If count is 0, old versions are removed rather than rotated. (source : man)







share|improve this answer
















  • 2




    no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
    – keen
    Jun 21 '16 at 20:33












up vote
1
down vote



accepted







up vote
1
down vote



accepted






it's a possibility and you need to test :



cat /etc/logrotate.d/customapp

/var/log/app/*.old
daily
missingok
rotate 0
notifempty



Why rotate 0 ?




If count is 0, old versions are removed rather than rotated. (source : man)







share|improve this answer












it's a possibility and you need to test :



cat /etc/logrotate.d/customapp

/var/log/app/*.old
daily
missingok
rotate 0
notifempty



Why rotate 0 ?




If count is 0, old versions are removed rather than rotated. (source : man)








share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 15 '15 at 16:05









colundrum

1262




1262







  • 2




    no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
    – keen
    Jun 21 '16 at 20:33












  • 2




    no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
    – keen
    Jun 21 '16 at 20:33







2




2




no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
– keen
Jun 21 '16 at 20:33




no, this wont work. logrotate will only remove files it created (rotated). source: testing, since docu doesnt cover it.
– keen
Jun 21 '16 at 20:33












up vote
0
down vote













logrotate runs once daily and the script can be found here, /etc/cron.daily/logrotate (on CentOS 7). If you want to run it each hour, you first need to move it to /etc/cron.hourly/. Then for the above command the equivalent logrotate script might look like this,



$ cat /etc/logrotate.d/app

/var/log/app/*.old
hourly
rotate 0
firstaction
/usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete
endscript
nocreate
missingok
notifempty






share|improve this answer








New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
    – Scott
    Nov 22 at 5:44










  • If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
    – Tanveer
    Nov 22 at 6:36















up vote
0
down vote













logrotate runs once daily and the script can be found here, /etc/cron.daily/logrotate (on CentOS 7). If you want to run it each hour, you first need to move it to /etc/cron.hourly/. Then for the above command the equivalent logrotate script might look like this,



$ cat /etc/logrotate.d/app

/var/log/app/*.old
hourly
rotate 0
firstaction
/usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete
endscript
nocreate
missingok
notifempty






share|improve this answer








New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
    – Scott
    Nov 22 at 5:44










  • If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
    – Tanveer
    Nov 22 at 6:36













up vote
0
down vote










up vote
0
down vote









logrotate runs once daily and the script can be found here, /etc/cron.daily/logrotate (on CentOS 7). If you want to run it each hour, you first need to move it to /etc/cron.hourly/. Then for the above command the equivalent logrotate script might look like this,



$ cat /etc/logrotate.d/app

/var/log/app/*.old
hourly
rotate 0
firstaction
/usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete
endscript
nocreate
missingok
notifempty






share|improve this answer








New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









logrotate runs once daily and the script can be found here, /etc/cron.daily/logrotate (on CentOS 7). If you want to run it each hour, you first need to move it to /etc/cron.hourly/. Then for the above command the equivalent logrotate script might look like this,



$ cat /etc/logrotate.d/app

/var/log/app/*.old
hourly
rotate 0
firstaction
/usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete
endscript
nocreate
missingok
notifempty







share|improve this answer








New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Nov 22 at 5:00









Tanveer

1




1




New contributor




Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Tanveer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
    – Scott
    Nov 22 at 5:44










  • If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
    – Tanveer
    Nov 22 at 6:36

















  • So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
    – Scott
    Nov 22 at 5:44










  • If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
    – Tanveer
    Nov 22 at 6:36
















So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
– Scott
Nov 22 at 5:44




So basically you're saying that logrotate can't do what the OP wants, so, if they have a business policy that says they must use logrotate, then the solution is to use logrotate as a vehicle to run their find command every hour. OKAAAAAAY. I would warn the OP: this solution might be considered a policy violation.
– Scott
Nov 22 at 5:44












If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
– Tanveer
Nov 22 at 6:36





If you don't put, firstaction /usr/bin/find /var/log/app/ -name "*.old" -mtime +1 -delete endscript logrotate will not remove the source log file.
– Tanveer
Nov 22 at 6:36


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f229807%2fdelete-files-only-with-logrotate%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?