Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file cleanup with cron 1

Status
Not open for further replies.

Noway2

Programmer
May 28, 2009
1,406
US
I have a question regarding a script in my crontab file. In my crontab, I have the following entries:
10 2 * * * root find /var/lib/amavis/virusmails/ -mtime +31 -exec rm {} \;
15 2 * * * root find /var/lib/amavis/tmp/ -mtime +31 -exec rm -r {} \;

These entries are designed to delete any messages in my email quarantine folder that are older than 31 days. The folder structure is a set of sub directories (a-z, A-Z, and 0-9) under the virusmails folder. The scripts appear to be functioning as desired, but with one annoying side effect. The scripts also attempt to remove the directories as I receive a daily email from the Cron Daemon reporting entries like this: rm: cannot remove `/var/lib/amavis/virusmails/h': Is a directory

How could I change the script to delete only the contents of the directories instead of the directories so that Cron doesn't report this error?
 
Hi

Just tell it :
Code:
10 2     * * *     root     find /var/lib/amavis/virusmails/ [highlight]-type f[/highlight] -mtime +31 -exec rm {} \;
15 2     * * *     root     find /var/lib/amavis/tmp/ [highlight]-type f[/highlight] -mtime +31 -exec rm -r {} \;

Feherke.
 
Thank You very much. You are a genius!

As follow up to your email, I looked in the man pages for -type. Once I knew what to look for it made perfect sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top