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:
Thanks in advance for any insight into what's going on.
ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f {}" \;'
?find . -type d -iname *.blah -print0 | xargs -0 -I {} rm -rf "{}"
rm -f
(without-r
) and is not trying to remove directories. (2) Your solution doesn’t make much sense. (2a) It would create a race condition, where thefind
and thexargs
are running concurrently. It would still be possible forxargs
to remove a directory whilefind
is still traversing it. (2b) You might believe that your suggestion is equivalent to … (Cont’d)find . -type d -iname *.blah -print0 > tmpfile; xargs -0 -I {} rm -rf "{}" < tmpfile
. It’s not, because, as I said, processes in a pipeline run concurrently (while;
forces sequential execution). But even if you did that, it would just move the “No such file or directory” errors fromfind
toxargs
/rm
. (3) Please don’t say-iname *.blah
. Deferred wildcards should be quoted:-iname '*.blah'
.