From owner-freebsd-questions@FreeBSD.ORG Wed Aug 17 21:59:59 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C66A516A41F for ; Wed, 17 Aug 2005 21:59:59 +0000 (GMT) (envelope-from matt@atopia.net) Received: from neptune.atopia.net (neptune.atopia.net [209.128.231.90]) by mx1.FreeBSD.org (Postfix) with ESMTP id 80DB843D53 for ; Wed, 17 Aug 2005 21:59:59 +0000 (GMT) (envelope-from matt@atopia.net) Received: by neptune.atopia.net (Postfix, from userid 1001) id E8F56617E; Wed, 17 Aug 2005 17:59:58 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by neptune.atopia.net (Postfix) with ESMTP id E6C066150 for ; Wed, 17 Aug 2005 17:59:58 -0400 (EDT) Date: Wed, 17 Aug 2005 17:59:58 -0400 (EDT) From: Matt Juszczak To: freebsd-questions@freebsd.org Message-ID: <20050817175235.D92325@neptune.atopia.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: OT: Removing 14 day old messages, my script... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 21:59:59 -0000 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;