[TriLUG] Folder size control with procmail

Jon Carnes jonc at nc.rr.com
Fri Jun 7 19:05:43 EDT 2002


On Friday 07 June 2002 12:28 pm, Mike McLean wrote:
> Is there any particular tool you use in that cronjob?
>
> Jon Carnes wrote:
> > Cronjob.  I use a script kicked off by cron once a week to parse
> > through the mail my folks leave on the mailserver.  I delete anything
> > older than 2 months. Of course I still use the default mbox format.
>
> _______________________________________________

Here is a copy of the one I run on my external mail server.  It's a *much* 
simpler script but essentially does the same thing as my interior script - 
except it runs only monthly and does not save the first "message" in the 
spool (my internal popper uses the first message to determine the last time 
that the spool was downloaded, and by what client - that message is purely 
administrative and is never downloaded).  

Note, for me this script takes less than 3 minutes to run on about 200 
spools.  If it got longer I would have to use lock files instead of turning 
off access to the spools.

#! /bin/bash
# This script searches through the mail spools and deletes any mail from the
# previous month (if you run it on the first, modify the date to:
#   MON=`date -d "2 months ago" "+%b"`
#
MON=`date -d "1 month ago" "+%b"`
#
# Stop SMTP from doing local delivery
/etc/rc.d/init.d/sendmail stop 
# Turn off POP - a function of xinetd
/etc/rc.d/init.d/xinetd stop
# Stop any current pop sessions
ps ax |grep pop |grep -v grep |cut -f1 "-d " |xargs kill 2>/dev/null
#
cd /var/spool/mail
for i in `ls`
  do
  AN1=`grep -nB1 "^From " $i |grep -A1 [0-9]-$ |grep $MON \
          |tail -1|cut -f1 -d:`
  if [ ! "xxx$AN1" = "xxx" ]; then
    sed -n "$AN1, $ p" $i >$i.tmp
    mv $i.tmp $i
    # echo $i $AN1
  fi
done
#
# Start up POP services again
/etc/rc.d/init.d/xinetd start
# Start up Sendmail services again
/etc/rc.d/init.d/sendmail start




More information about the TriLUG mailing list