批量添加Spamassassin规则
出处:http://www.yijiaqing.cn/blog/article.asp?id=470 作者:松鼠 时间:2013-4-25 0:14:05
如果要添加一大堆Spamassassin规则,一个一个写起来非常痛苦,在网上看到一个专门来处理Spamassassin自定义规则的脚本。原文地址:http://bbs.nettf.net/forums/index.php?showtopic=51798脚本文件# cat add-spam-rules.sh#!/bin/sh## Add spam rule script# compile by Liu Hongguang# 2006/03/03# Website: http://www.nettf.netPAHT=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbinBODYFILE=body_spam.listSUBJECTFILE=subject_spam.listRULEFILE=Custom_rules.cfRULENUM=500DEFAULTHIT=2DATE=`date '+%Y/%m/%d %H:%M'`echo "#" > $RULEFILEecho "# Create date: $DATE " >> $RULEFILEecho "#" >> $RULEFILEcat $SUBJECTFILE | awk \'{if ($1=="") next; #如果内容为空则跳过if ($2=="" || $2<=0) $2='$DEFAULTHIT'; #当分数为空的时候则设置分数为默认的DEFAULTHITif (i=="")i='$RULENUM'; #定义起始规则号为RULENUMelsei++; #规则号自动加1print "";print "header CN_SUBJECT_"i" Subject =~ /"$1"/";print "describe CN_SUBJECT_"i" Subject contains \""$1"\"";print "score CN_SUBJECT_"i" "$2;}' >> $RULEFILELINE=`sed '/^$/d' $SUBJECTFILE | wc -l | tr -d "\ "` #得到$SUBJECTFILE文件的行书RULENUM=`expr $RULENUM + $LINE` #定义起始规则号不从默认的500开始而从新的开始cat $BODYFILE | awk \'{if ($1=="") next;if ($2=="" || $2<=0) $2='$DEFAULTHIT';if (i=="")i='$RULENUM';elsei++;print "";print "body CN_BODY_"i" /"$1"/";print "describe CN_BODY_"i" Body contains \""$1"\"";print "score CN_BODY_"i" "$2;}' >> $RULEFILEecho "Done!"exit 0标题文件# cat subject_spam.list特价机票 3机票特价 3代开发票 5.5正文文件# cat body_spam.list加盟热线 5.5财税咨询 5.5所有票据 5.5 文件中前面为内容,后面的数字是评分,当内容匹配,就添加后面的评分,内容和数字之间用<TAB>来隔开,执行add-spam-rules.sh就可以生成Custom_rules.cf,然后把这个文件复制到/usr/share/spamassass目录,重新加载Amavisd即可。