No such file or directory With find -exec rm -f ;

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a purge job that runs daily to clean up logs older than 30 days.
find /dir/app/logs -mtime +30 -exec rm -f ;
I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.
The job runs by executing the command:
ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"
against the remote server.
I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.
Currently I'm testing changing ; to + as suggested here:
find - exec rm vs -delete
Thanks in advance for any insight into what's going on.
ssh find
add a comment |Â
up vote
0
down vote
favorite
I have a purge job that runs daily to clean up logs older than 30 days.
find /dir/app/logs -mtime +30 -exec rm -f ;
I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.
The job runs by executing the command:
ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"
against the remote server.
I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.
Currently I'm testing changing ; to + as suggested here:
find - exec rm vs -delete
Thanks in advance for any insight into what's going on.
ssh find
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotesssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
â lightwing
Jan 5 at 18:33
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a purge job that runs daily to clean up logs older than 30 days.
find /dir/app/logs -mtime +30 -exec rm -f ;
I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.
The job runs by executing the command:
ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"
against the remote server.
I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.
Currently I'm testing changing ; to + as suggested here:
find - exec rm vs -delete
Thanks in advance for any insight into what's going on.
ssh find
I have a purge job that runs daily to clean up logs older than 30 days.
find /dir/app/logs -mtime +30 -exec rm -f ;
I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.
The job runs by executing the command:
ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"
against the remote server.
I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.
Currently I'm testing changing ; to + as suggested here:
find - exec rm vs -delete
Thanks in advance for any insight into what's going on.
ssh find
asked Jan 5 at 18:17
lightwing
96
96
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotesssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
â lightwing
Jan 5 at 18:33
add a comment |Â
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotesssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
â lightwing
Jan 5 at 18:33
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes
ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?â lightwing
Jan 5 at 18:33
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes
ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?â lightwing
Jan 5 at 18:33
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
After some time off and more googling around, this solution may fix the issue:
find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete
It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.
To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:
find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
After some time off and more googling around, this solution may fix the issue:
find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete
It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.
To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:
find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete
add a comment |Â
up vote
0
down vote
After some time off and more googling around, this solution may fix the issue:
find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete
It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.
To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:
find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete
add a comment |Â
up vote
0
down vote
up vote
0
down vote
After some time off and more googling around, this solution may fix the issue:
find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete
It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.
To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:
find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete
After some time off and more googling around, this solution may fix the issue:
find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete
It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.
To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:
find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete
edited Feb 6 at 18:58
answered Jan 16 at 13:57
lightwing
96
96
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f415044%2fno-such-file-or-directory-with-find-exec-rm-f%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Ssh introduces another level of quoting; thereâÂÂs another question on it here somewhere.
â Jeff Schaller
Jan 5 at 18:19
Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes
ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?â lightwing
Jan 5 at 18:33