Delete files only with logrotate
Clash 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 ;
logrotate
add a comment |
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 ;
logrotate
-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 atman logrotate
?
– Archemar
Sep 15 '15 at 13:04
add a comment |
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 ;
logrotate
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
logrotate
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 atman logrotate
?
– Archemar
Sep 15 '15 at 13:04
add a comment |
-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 atman 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
add a comment |
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)
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
add a comment |
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
New contributor
So basically you're saying thatlogrotate
can't do what the OP wants, so, if they have a business policy that says they must uselogrotate
, then the solution is to uselogrotate
as a vehicle to run theirfind
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 endscriptlogrotate
will not remove the source log file.
– Tanveer
Nov 22 at 6:36
add a comment |
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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
New contributor
So basically you're saying thatlogrotate
can't do what the OP wants, so, if they have a business policy that says they must uselogrotate
, then the solution is to uselogrotate
as a vehicle to run theirfind
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 endscriptlogrotate
will not remove the source log file.
– Tanveer
Nov 22 at 6:36
add a comment |
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
New contributor
So basically you're saying thatlogrotate
can't do what the OP wants, so, if they have a business policy that says they must uselogrotate
, then the solution is to uselogrotate
as a vehicle to run theirfind
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 endscriptlogrotate
will not remove the source log file.
– Tanveer
Nov 22 at 6:36
add a comment |
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
New contributor
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
New contributor
New contributor
answered Nov 22 at 5:00
Tanveer
1
1
New contributor
New contributor
So basically you're saying thatlogrotate
can't do what the OP wants, so, if they have a business policy that says they must uselogrotate
, then the solution is to uselogrotate
as a vehicle to run theirfind
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 endscriptlogrotate
will not remove the source log file.
– Tanveer
Nov 22 at 6:36
add a comment |
So basically you're saying thatlogrotate
can't do what the OP wants, so, if they have a business policy that says they must uselogrotate
, then the solution is to uselogrotate
as a vehicle to run theirfind
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 endscriptlogrotate
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
-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