[TriLUG] Script error?

Rick DeNatale rick.denatale at gmail.com
Thu Jul 14 11:38:22 EDT 2005


On 7/13/05, Brian Henning <lugmail at cheetah.dynip.com> wrote:

> Of course, always be extraordinarily careful when using -f with any command
> which offers it, particularly rm..

and particularly if the cron job is running as root.

A better approach might be to use xargs, something like:

find /var/spool/squirrelmail/attach -atime +2 | grep -v "\." | grep
-v _` | xargs -0 rm

All on one line.

The -print0 and -0 options to find and xargs respectively team up to
allow special characters such as spaces which might appear in the file
names. find will use nul characters instead of newlines as delimiters
and xargs will do the same.

However, the greps in the middle will screw things up because grep
will look for those newlines.  So we need to make find exclude  files
starting with . or _ in the names (since Lisa seems to want to do
this)

I think that this might do the job

find /var/spool/squirrelmail/attach -atime +2 \! \( -name "\.*" -or
-name "_*" \) | xargs -0 rm

The expression in find isn't exactly the same as the regexps that were
being used in grep.  It's probably a good idea to manually test just
the find part before putting it in a cron job to make sure it's doing
what you want.



More information about the TriLUG mailing list