Recently I noticed that there’s a lot of temporary files in the /tmp directory on my mail server … all the files have spamassassin in the file name. I figured that in some cases, SpamAssassin (or programs it calls) isn’t cleaning up properly.
I whipped up this script that will clean up any spamassassin files & directories that are older than a set number of minutes (60 in my case)…
#!/bin/sh
AGE=60
if [ "$1" == "--test" ]
then
CMD="-exec echo"
echo "$0: test mode"
else
CMD="-exec"
fi
/usr/bin/find /tmp \
-mmin +$AGE \
-name spamassassin.ocr* \
$CMD /bin/rm -f '{}' \;
/usr/bin/find /tmp \
-maxdepth 1 \
-mmin +$AGE \
-type d \
-name .spamassassin\* \
$CMD /bin/rm -rf '{}' \;
If you run the script with a parameter of ‘–test’, it will just show the commands it would have executed.
I put the script in /etc/cron.hourly directory so it gets executed every hour.
March 14th, 2007 at 9:29 pm
tmpreaper does something very similar to this. We recommend it as part of the SquirrelMail package to clean up abandoned attachments.
Nice script
March 14th, 2007 at 10:23 pm
Looks like tmpreaper is an analog to tmpwatch … neither of which seems to be able to manage generic file specs.
As for the script being “nice” … I guess that’s true if you like simplicity.