Spamandclam.sh
From Kolab wiki
[edit]
spamandclam.sh
This bash script will update your spam dbs from a central shared folder. It needs amail.pl to send confirmation email. The script also updates to the latest clamav antivirus patterns though this is not really required. The Kolab Server updates every hour anyway.
#!/kolab/lib/openpkg/bash # filename: spamandclam.sh # version: 0.1 # Author: Hamish Gough <lists@subvs.co.uk> # Description: Updates clamav and spamassassin for kolab # Change below to match your setup: # MAILFROM: Who the mail result will be from # MAILTO: Who to send the result to # MAILBODY: Optional text file to put in the mail body - default is blank (/dev/null) # AMAILLOC: Full path to amail.pl # SALEARNCMD1: Command to run sa-learn (the default checks a shared folder called "spam" # you can make this shared folder in the kolab2 web admin, or with cyradm) # FRESHCLAMCMD: Command to update clamav # LOGFILE: Full path to temp log file for confirmation email MAILFROM="it@mydomain.com" MAILTO="it@mydomain.com" MAILBODY="/dev/null" AMAILLOC="/data2/amail.pl" SALEARNCMD1="/kolab/bin/sa-learn --spam /kolab/var/imapd/spool/domain/*/shared^spam/[1-9]* --dbpath /kolab/var/amavisd/.spamassassin" FRESHCLAMCMD="/kolab/bin/freshclam" LOGFILE="/data2/spamlog.txt" echo "## SPAMASSASSIN ##" > $LOGFILE echo "" >> $LOGFILE echo "I ran the following command:" >> $LOGFILE echo $SALEARNCMD1 >> $LOGFILE echo "And it told me this:" >> $LOGFILE $SALEARNCMD1 >> $LOGFILE echo "" >> $LOGFILE echo "## CLAMAV ##" >> $LOGFILE echo "" >> $LOGFILE echo "I ran the following command:" >> $LOGFILE echo $FRESHCLAMCMD >> $LOGFILE echo "And it told me this:" >> $LOGFILE $FRESHCLAMCMD >> $LOGFILE echo $AMAILLOC -s "Spamassassin training and antivirus updates" -r $MAILFROM -a $LOGFILE $MAILTO < $MAILBODY
[edit]
spam.sh
Second example (tested on Kolab 2.2.1 RC1), you can run it as kolab-r from cron.
This example deletes after learning the items in shared spam and ham folder.
It start sa-learn only if it find emails to learn in one of the both shared folders,
so you can run it every 15 minutes from cron.
We don't need to start freshclam anymore from this script.
Put it in to /kolab/data directory together with amail.pl. Then chown kolab-r:kolab-r -R /kolab/data
#!/kolab/lib/openpkg/bash
# filename: spam.sh
# version: 0.1
# Description: Updates spamassassin for kolab
MAILFROM="root@example.com"
MAILTO="name@example.com"
MAILBODY="/dev/null"
AMAILLOC="/kolab/data/amail.pl"
SALEARNCMD1="/kolab/bin/sa-learn --dbpath /kolab/var/amavisd/.spamassassin --spam /kolab/var/imapd/spool/domain/n/example.com/s/shared^spam --ham /kolab/var/imapd/spool/domain/n/example.com/s/shared^ham"
SALEARNCMD2="/kolab/bin/sa-learn --dump magic --dbpath /kolab/var/amavisd/.spamassassin"
SALEARNCMD3="rm -v /kolab/var/imapd/spool/domain/n/example.com/s/shared^spam/*"
SALEARNCMD4="/kolab/bin/cyrreconstruct -rf shared.spam@example.com"
SALEARNCMD5="rm -v /kolab/var/imapd/spool/domain/n/example.com/s/shared^ham/*"
SALEARNCMD6="/kolab/bin/cyrreconstruct -rf shared.ham@example.com"
LOGFILE="/kolab/data/spamlog.txt"
if (ls /kolab/var/imapd/spool/domain/n/example.com/s/shared^spam/[0-9]* >/dev/null 2>&1) || (ls /kolab/var/imapd/spool/domain/n/example.com/s/shared^ham/[0-9]* >/dev/null 2>&1); then
echo "## SPAMASSASSIN ##" > $LOGFILE
echo "" >> $LOGFILE
echo "I ran the following command:" >> $LOGFILE
echo $SALEARNCMD1 >> $LOGFILE
echo "And it told me this:" >> $LOGFILE
$SALEARNCMD1 >> $LOGFILE
echo "" >> $LOGFILE
echo "Result:" >> $LOGFILE
$SALEARNCMD2 >> $LOGFILE
echo "" >> $LOGFILE
echo "CleanUp:" >> $LOGFILE
$SALEARNCMD3 >> $LOGFILE
$SALEARNCMD5 >> $LOGFILE
echo "" >> $LOGFILE
echo "Cyrreconstruct:" >> $LOGFILE
$SALEARNCMD4 >> $LOGFILE
$SALEARNCMD6 >> $LOGFILE
$AMAILLOC -s "Spamassassin training" -f $MAILFROM -a $LOGFILE $MAILTO < $MAILBODY
else
exit 1
fi
exit 0
