OT: Removing 14 day old messages, my script...
Matt Juszczak
matt at atopia.net
Wed Aug 17 21:59:59 GMT 2005
Hi all,
I've created the following script to remove 14 day old messages.
expunge-check.pl (not shown here, but CALLED from the script below) takes
a single email messages on STDIN and then checks whether the date of that
message is 14 days old or greater. If it is, it skips it. If it is NOT,
it writes it to a file. So at the end of the formmail -s call below,
there is now a Spam.tmp file in $HOME/mail for the user. The script below
then moves that file to their productive Spam folder, and it moves onto
the next user.
I wish there was an easier way to do this. Instead of creating a
NEW file with just the messages we have to keep, I wish that we could just
remove the specific mail message from the actual Spam folder (maybe by
passing the From: or the message itself possibly). That way, we wouldn't
have to do moving, chowning, and a bunch of locking (and I know I'm not
locking with flock below either, which is also a problem).
With 3000 users, the script below takes all day to run, about 2 minutes
per user. Reason being is it has to go through ALL messages, even if they
are 3 days old, because it has to write those to a separate file.
Is there an easier way to do this?
Thanks!
-Matt
--- begin snip ---
for x in `ls /home/*/mail/Spam`
do
USERNAME=`echo $x | awk -F'/' '{ print $3 }'`;
SIZE=`du $x | awk -F' ' '{ print $1 }'`;
if [ "$SIZE" -lt "5120" ]
then
echo "Skipping $USERNAME ($SIZE)";
else
echo "Analyzing $USERNAME ($SIZE)";
# Remove existing Spam.tmp
if [ -f "/home/$USERNAME/mail/Spam.tmp" ]
then
rm /home/$USERNAME/mail/Spam.tmp;
fi
# Create locks
touch /home/$USERNAME/mail/Spam.lock
# Call Formmail recursively
formail -s /usr/local/mailclean/expunge-check.pl $USERNAME < $x
# Remove locks
rm /home/$USERNAME/mail/Spam.lock
# Move Spam.tmp and CHOWN!
if [ -f "/home/$USERNAME/mail/Spam.tmp" ]
then
mv /home/$USERNAME/mail/Spam.tmp /home/$USERNAME/mail/Spam;
chown $USERNAME:users /home/$USERNAME/mail/Spam;
fi
fi
done;
More information about the freebsd-questions
mailing list