These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX03/Bayesian Learning Script

Classnotes | UNIX03 | RecentChanges | Preferences

One of the last steps we need to do is setup our SpamAssassin learning system. As you've seen SA will automatically add very SPAMMY or NOT-SPAMMY messages to its Bayesian database. In addition to that, we want to give our users the opportunity to help fine-tune the system. Remember the spam and notspam accounts that we setup earlier? Well this is where we put them to use.

First, a little explanation. When a user sends an email message to (substitute your server's name), it will be delivered to a single mbox file, in this case /var/mail/spam. Mail to will be delivered to /var/mail/notspam. Once a day (or more if you want), we want the system to read in all the email in these mbox files and add them to the Bayesian statistics database. To accomplish this, we'll write a script and call it using cron.

Create a file using your text editor and call it /usr/local/sbin/ Cut and paste the following commands into this file:


 if [ -e /var/mail/spam ]; then
 /usr/bin/sa-learn --spam -p /var/lib/amavis/.spamassassin/user_prefs   --mbox /var/mail/spam
 rm /var/mail/spam > /dev/null

 if [ -e /var/mail/notspam ]; then
 /usr/bin/sa-learn --ham -p /var/lib/amavis/.spamassassin/user_prefs   --mbox /var/mail/notspam
 rm /var/mail/notspam > /dev/null

 /usr/bin/sa-learn --rebuild -p /var/lib/amavis/.spamassassin/user_prefs

Now run the following command to make it executable:

 # chmod 500 /usr/local/sbin/ 

Next, we want to add it to our list of list of scheduled programs.

 # crontab -e 

Add the following 2 lines at the bottom of the file:

 # spamassassin bayesian learning script
 05 0 * * * /usr/local/sbin/

This will cause the script to get run every night at 12:05 am.

Classnotes | UNIX03 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited June 7, 2003 2:48 am (diff)
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.