sa-learn
Glenn Steen
glenn.steen at gmail.com
Mon May 29 14:31:44 IST 2006
Hi Phil,
On 27/05/06, --[UxBoD]-- <uxbod at splatnix.net> wrote:
> Hi,
>
> i use MailScanner with Postfix and was wondering how I get newly spam entered to the bayes database. I have created a little script
> that polls our accounts :-
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
> #!/bin/bash
>
> LOCK_FILE=/var/lock/subsys/spam_check.lock
>
> if [ -f ${LOCK_FILE} ]; then
> logger -p local0.info -t learn-spam "Still running !"
> exit
> fi
>
> touch ${LOCK_FILE}
>
> for user in spam xyz abc
> do
> typeset -i count=0
>
> for file in /home/${user}/.maildir/.LEARN-SPAM/cur/*
> do
> if [ -f ${file} ]; then
> sa-learn --spam ${file} && rm ${file}
> let count=${count}+1
> fi
> done
>
> for file in /home/${user}/.maildir/.LEARN-HAM/cur/*
> do
> if [ -f ${file} ]; then
> sa-learn --ham ${file} && cat ${file} | \
> spamassassin -d > ${file} && mv ${file} /home/${user}/.maildir/cur
You have a potential "read and write the same file, at the same time"
situation there, with the second command sequence (cat reads, and the
redirect writes). Normally, you might not get any problem from this,
but it is potentially unsafe. Best is to change that to somethhing
like
sa-learn --ham ${file} && cat ${file} | \
spamassassin -d > ${file}.tmp && mv
${file}.tmp /home/${user}/.maildir/cur/$file
(watch out for wrapping:-).
> fi
> done
> done
>
> if [ ${count} -gt 0 ]; then
> logger -p local0.info -t learn-spam "${count} email(s) processed"
> fi
>
> trap "rm -f ${LOCK_FILE}" exit
>
> exit 0
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
>
> but for this to work I presume that it will need to be run as the effective user ie. Postfix ?
>
Depending on a few things.... Then yes. "su postfix -s /bin/sh -c
<command(s)>" is your friend:-)...
--
-- Glenn
email: glenn < dot > steen < at > gmail < dot > com
work: glenn < dot > steen < at > ap1 < dot > se
More information about the MailScanner
mailing list