SeLLeRoNe
Super Moderator
Yes, the problem was that the script i'd made was making a single place where to save bayes_* files in /root/.spamassassin since the sa-learn command was running at root level.
Since there are many accounts and many emails, the files was growing very fast and the sa-learn command was going to take all disk I/O causing server incredible slow.
I've fixed the script now, at this moment the script run as root but run the sa-learn command at user level, so the /home/USER/.spamassassin folder is used for bayes and for user_pref file.
At this time, the script check for Maildir/.Junk/cur-new for Spam and Maildir/cur-new for HAM (taken from INBOX itself, that's why files grow, if user doesnt use other folder than INBOX the scan would take more)
DA for now use Maildir/.INBOX.Spam as default folder for Spam, but i know that John is studing a way to change that in DA code (i suppose) to make it editbale, or at least to change it to Mildir/.Junk (since is the default folder used from most client for that purpose).
The script is this one:
Hope you enjoy it Feel free to edit it as you need to, specially for the Spam folder changing:
FILESPAM=${1}/.Junk
to
FILESPAM=${1}/.INBOX.spam
Also, if you want a folder different from INBOX as folder for teach the non-Spam change:
FILEHAM=${1}
to
FILEHAM=${1}/.NON-SPAM-FOLDER
USAGE:
- Save it as filename you prefer (ex. script.sh)
- Run it with no extra info will run on all users (ex ./script.sh)
- Run it with username as extrafilm will run the script just for specified user (ex. ./script.sh admin)
Regards
Since there are many accounts and many emails, the files was growing very fast and the sa-learn command was going to take all disk I/O causing server incredible slow.
I've fixed the script now, at this moment the script run as root but run the sa-learn command at user level, so the /home/USER/.spamassassin folder is used for bayes and for user_pref file.
At this time, the script check for Maildir/.Junk/cur-new for Spam and Maildir/cur-new for HAM (taken from INBOX itself, that's why files grow, if user doesnt use other folder than INBOX the scan would take more)
DA for now use Maildir/.INBOX.Spam as default folder for Spam, but i know that John is studing a way to change that in DA code (i suppose) to make it editbale, or at least to change it to Mildir/.Junk (since is the default folder used from most client for that purpose).
The script is this one:
Code:
#!/bin/sh
###############################################################################
# #
# Crazy Network #
# #
# http://www.CrazyNetwork.it #
# #
# [email protected] #
# #
###############################################################################
if [ "$1" != "" ]; then
if [ -d /usr/local/directadmin/data/users/$1/ ]; then
COMMAND="echo $1"
else
echo "Invalid user"
fi
else
COMMAND="ls /usr/local/directadmin/data/users/"
fi
for DA_USER in `$COMMAND`
do
echo ""
echo "#########################################################################################"
echo "Starting user $DA_USER"
echo ""
DA_HOME=/home/${DA_USER}
touch $DA_HOME/sa-learn.log
chown $DA_USER:$DA_USER $DA_HOME/sa-learn.log
#set this to 1 if you want the spam be removed after the run
DELETE_SPAM_DATA=0
learn_Maildir()
{
FILESPAM=${1}/.Junk
FILEHAM=${1}
ACCOUNT="`echo $maildir | cut -d/ -f6`@$d"
if [ "$ACCOUNT" = "@" ]; then
ACCOUNT="$DA_USER@$HOSTNAME"
fi
if [ -e ${FILESPAM}/new ] || [ -e ${FILESPAM}/cur ]; then
echo "Learning SPAM for account ${ACCOUNT}";
su - $DA_USER -s /bin/sh -c "nice sa-learn --no-sync --spam ${FILESPAM}/{cur,new} > ${DA_HOME}/sa-learn.log" >/dev/null
cat $DA_HOME/sa-learn.log
fi
if [ -e ${FILEHAM}/new ] || [ -e ${FILEHAM}/cur ]; then
echo "Learning HAM for account $ACCOUNT";
su - $DA_USER -s /bin/sh -c "nice sa-learn --no-sync --ham ${FILEHAM}/{cur,new} > ${DA_HOME}/sa-learn.log" >/dev/null
cat $DA_HOME/sa-learn.log
fi
if [ "$DELETE_SPAM_DATA" -eq 1 ]; then
rm -f ${FILESPAM}/new/*
fi
}
if [ -e $DA_HOME/Maildir ]; then
echo "Starting main E-Mail account for user $DA_USER"
echo "-----------------------------------------------------------------------------------------"
learn_Maildir $DA_HOME/Maildir
echo "-----------------------------------------------------------------------------------------"
echo ""
fi
for d in `ls $DA_HOME/imap`; do
{
> $DA_HOME/sa-learn.log
echo "Starting E-Mail accounts for domain $d"
echo "-----------------------------------------------------------------------------------------"
DOMAIN_DIR=${DA_HOME}/imap/${d}
if [ -h $DOMAIN_DIR ]; then
echo "No E-Mail accounts for domain $d"
echo "-----------------------------------------------------------------------------------------"
echo ""
continue;
fi
for maildir in `ls -d ${DOMAIN_DIR}/*/Maildir 2>/dev/null`; do
{
learn_Maildir ${maildir}
};
done;
if [ "`cat $DA_HOME/sa-learn.log`" = "" ]; then
echo "No E-Mail accounts for domain $d"
fi
su - $DA_USER -s /bin/sh -c "nice sa-learn --sync" >/dev/null
echo "-----------------------------------------------------------------------------------------"
echo ""
};
done;
echo "Statistics for user $DA_USER:"
echo "-----------------------------------------------------------------------------------------"
su - $DA_USER -s /bin/sh -c "nice sa-learn --dump magic > $DA_HOME/sa-learn.log" >/dev/null
cat $DA_HOME/sa-learn.log
echo "-----------------------------------------------------------------------------------------"
rm -rf $DA_HOME/sa-learn.log
echo "#########################################################################################"
done;
exit 0;
Hope you enjoy it Feel free to edit it as you need to, specially for the Spam folder changing:
FILESPAM=${1}/.Junk
to
FILESPAM=${1}/.INBOX.spam
Also, if you want a folder different from INBOX as folder for teach the non-Spam change:
FILEHAM=${1}
to
FILEHAM=${1}/.NON-SPAM-FOLDER
USAGE:
- Save it as filename you prefer (ex. script.sh)
- Run it with no extra info will run on all users (ex ./script.sh)
- Run it with username as extrafilm will run the script just for specified user (ex. ./script.sh admin)
Regards
Last edited: