Cronjob to use sa-learn to teach spamassassin - Maildir

mr.suchy

Verified User
Joined
Oct 1, 2015
Messages
24
Hi everyone,

I want to create a script like in this article: http://help.directadmin.com/item.php?id=358 but when I run script to test I have error:

Code:
: command not found
: command not found
: command not found
'each.sh: line 9: syntax error near unexpected token `
'each.sh: line 9: `learn_Maildir()

Where is the problem ? Thanks for help.

Kind regards
 
Post your exact script and we can tell you, I am guessing it differs from the one you linked because I don't see anything wrong with that one.
 
I using Linux Centos. My script:
Code:
#!/bin/sh

DA_USER=psoft
DA_HOME=/home/${DA_USER}

#set this to 1 if you want the spam be removed after the run
DELETE_TEACH_DATA=0

learn_Maildir()
{
            FILESPAM=${1}/.INBOX.teach-isspam
            FILEHAM=${1}/.INBOX.teach-isnotspam

            if [ -e ${FILESPAM}/new ] || [ -e ${FILESPAM}/cur ]; then
                        echo "learning spam via ${FILESPAM}...";
                        sa-learn --no-sync --spam  ${FILESPAM}/{cur,new}
            fi

            if [ -e ${FILEHAM}/new ] || [ -e ${FILEHAM}/cur ]; then
                        echo "";
                        echo "learning ham via $FILEHAM...";
                        sa-learn --no-sync --ham ${FILEHAM}/{cur,new}
            fi

     if [ "$DELETE_TEACH_DATA" -eq 1 ]; then
         rm -f ${FILESPAM}/new/* ${FILESPAM}/cur/*
         rm -f ${FILEHAM}/new/* ${FILEHAM}/cur/*
     fi
}

if [ -e $DA_HOME/Maildir ]; then
     learn_Maildir $DA_HOME/Maildir
fi

for d in `ls $DA_HOME/imap`; do
{
            DOMAIN_DIR=${DA_HOME}/imap/${d}
            if [ -h $DOMAIN_DIR ]; then
                        continue;
            fi

            for maildir in `ls -d ${DOMAIN_DIR}/*/Maildir 2>/dev/null`; do
            {
                learn_Maildir ${maildir}
            };
            done;
};
done;

echo "";
echo "syncing...";
sa-learn --sync

echo "";
echo "current status:"
sa-learn --dump magic

exit 0;
 
This is your script named each.sh ? I don't see any issue especially at line 9 like the first post mentions. Perhaps we need to see exactly how you were executing this script and the exact out it gave.
 
Code:
./teach.sh
So executing ./teach.sh outputs:
: command not found
: command not found
: command not found
'each.sh: line 9: syntax error near unexpected token `
'each.sh: line 9: `learn_Maildir()

Something isn't right, you have 3 unknown ": command not found" errors and then it says 'each.sh has an error. It should show teach.sh unless something else is happening.
 
Back
Top