Posts Tagged ‘cron’
How to trim/pack Spamassassin´s auto-whitelist
The problem: if a mailbox has spam filtering enabled, Spamassasin creates and maintain an auto-whitelist for each of it, and this file increases in time. Generally, every admin wants to trim it or limit it’s size.
Solution 1: On Debian Etch servers running Plesk / QMail & Spamassassin, each mail user has it’s own config files /var/qmail/mailnames/domain/user/.spamassassin. You can add bayes_expiry_max_db_size to each user local.cf or default.cf, but it’s not a global solution and it’s hard to maintain to new users.
Solution 2: Another approach is to run a job (let’s say weekly) to automatically trim the auto-whitelist for all mail users on the server. It’s fast, easy … and you can forget about this in the cron job
After a bit of googling, we found a script to trim old and unused records from an auto-whitelist file here. (in the rest of the article, we’ll assume that the above script is saved as /root/bin/trim-spamassasin-auto-whitelist and it’s made executable with chmod +x)
So far, so good, but the above script works on only one given auto-whitelist.
We can use some bash/sh scripting to find all the mail users settings and apply the trimming to every file, as follows:
#!/bin/sh # Trim old records and unused space from mail users's .spamassasin/auto-whitelist # (c) 2008 Frontline softworks, www.frontline.ro # Visit http://sandbox.frontline.ro for updates # Trim Utility Location # Get if from http://www.deepnet.cx/~kdeugau/spamtools/trim_whitelist TrimUtility='/root/bin/trim-spamassasin-auto-whitelist' # Users mail storage folder UsersMail='/var/qmail/mailnames/' # Auto-whitelist file name AutoFileName='auto-whitelist' # Find all Plesk users auto-whitelist for file in `find $UsersMail -type f -name $AutoFileName`; do # Run the trim tool on this mailbox # See http://www.deepnet.cx/~kdeugau/spamtools/trim_whitelist $TrimUtility $file; # After the file is trimmed, there is an '-old' file which we don't need it anymore if [ -e $file'-old' ]; then rm $file'-old'; fi; done
Save the above script in /etc/cron.weekly and wait for the weekly run.
Have fun playing …
Posted on May 13th, 2008 in Debian, Linux, Plesk | 1 Comment »














