Four recommendations for troubleshooting:

1) use a test command that is not so destructive when it fails
2) log output
3) run it more frequently
4) include a positive control entry that you know should work and a
negative control that you know won't

For example, replace your original command:

20 1 * * * find /tmp -mtime +7 -type f -exec rm -f { } ';'

with this:

* * * * * find /tmp -mtime +7 -type f -exec ls -ld { } ';' >> /tmp/cron.log
2>&1

And place some positive/negative controls in your /tmp folder :

# touch -t 201901020304 /tmp/z.test.file.pos
# touch /tmp/z.test.file.neg

This is what shows in the log when cron runs:

# cat /tmp/cron.log
ls: cannot access '{': No such file or directory
ls: cannot access '}': No such file or directory

Looks like there's a space between the curly braces.  If I remove the space
...

# cat /tmp/cron.log
-rw-r--r-- 1 root root 0 Jan  2  2019 /tmp/z.test.file.pos

You might want to enable verbosity to the rm so that you can confirm what
it's doing:

* * * * * find /tmp -mtime +7 -type f -exec rm -v -f {} ';' >>
/tmp/cron.log 2>&1

# cat /tmp/cron.log
removed '/tmp/z.test.file.pos'

Once all looks good, adjust the time to when you want the command to run.

Good luck and let us know how things go.

Regards,
- Robert


On Sun, Dec 15, 2019 at 6:22 AM Rich Shepard <rshep...@appl-ecosys.com>
wrote:

> Yesterday I put this command in root's crontab:
>
> # remove all files in /tmp not modified in 7 days daily at 1:20
> 20 1 * * * find /tmp -mtime +7 -type f -exec rm -f { } ';'
>
> It is not working as I expected since there are files in /tmp as old as
> last
> August. There are also old directories not modified for months.
>
> Should I put this in a shell script and use 'test' first? Would the old
> subdirectories removal be fixed by changing the rm option to -rf without
> adversely affecting the results?
>
> Regards,
>
> Rich
> _______________________________________________
> PLUG mailing list
> PLUG@pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
_______________________________________________
PLUG mailing list
PLUG@pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to