Getting sa-update running automatically

Discussion in 'Tips/Tricks/Mods' started by bluethunder82, Feb 19, 2007.

  1. bluethunder82

    bluethunder82 Member

    In order to get your spam under control (well in the right direction) you can run the sa-update command and keep your 'rules' up-to-date. I'll outline what I have been using and am happy with. This may be obvious for some but hopefully helpful for others.

    First, sa-update needs to have two additional perl modules installed that are not needed required for spamassassin to function. These are LWP, Archive::Tar (Nov 2006 bug report). It was also mentioned that UserAgent.pm was not installed by default elsewhere in this forum. In order get all the required perl modules installed use the following command:

    Code:
    apt-get install libwww-perl libarchive-tar-perl
    This will allow the script sa-update to run and update your rules. However who wants to do this manually? I have created by own script that emails me the results of the updates each morning. For me this is preferred as I get many other daily emails from the servers so I can keep an eye on my background tasks.

    (I'll assume you know how to create and make executable the sh script)

    Code:
    #!/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/admispconfig/ispconfig/tools/spamassassin/usr/bin
    
    #########################################################################################################################
    #Written by Jason Shewchuk                                                                                              #
    #E-Mail: jason <> shewchuk.ca                                                                                           #
    #Version: 0                                                                                                             #
    #Date Created: Sept. 20, 2006                                                                                           #
    #Date Modified: Sept. 20, 2006                                                                                          #
    #Feel free to use and modify this script.  Let me know of changes you have made so I can learn and improve this script  #
    #########################################################################################################################
    
    #Today's date
    today=$(date +%Y_%m_%d)
    
    #Run sa-update
    /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update
    
    exitcode=$?     #Exit code from sa-update
    
    #Find version of sa-update
    version=$(/home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update -V | grep "sa-update")
    
    if [ $exitcode = 0 ]; then
            echo "An update was available, and was downloaded and installed successfully.  You are now running $version."  | formail -c -I"Subject: sa-update Updated for $today - Updated" -I"From: sa-update@localhost" -I"To: postmaster@{YOURDOMAIN.TLD}" -I"Received: from {YOURDOMAIN.TLD} ([{IP Address If You Wish}])" | sendmail postmaster@{YOURDOMAIN.TLD}
    
    elif [ $exitcode = 1 ]; then
            echo "No update was available.  You are still running $version." | formail -c -I"Subject: sa-update Update Status for $today - No Update" -I"From: sa-update@localhost" -I"To: postmaster@{YOURDOMAIN.TLD}" -I"Received: from {YOURDOMAIN.TLD} ([{IP Address If You Wish}])" | sendmail postmaster@{YOURDOMAIN.TLD}
    
    else
            echo "An error occured while attempting to download and extract updates.  You are still running $version." | formail -c -I"Subject: sa-update Update Status for $today - Error" -I"From: sa-update@localhost" -I"To: postmaster@{YOURDOMAIN.TLD}" -I"Received: from {YOURDOMAIN.TLD} ([{IP Address If You Wish}])" | sendmail postmaster@{YOURDOMAIN.TLD}
    fi
    
    exit 0
    You will need to update anything located in the {} brackets.

    Once this is done jump into your crontab.
    Code:
    crontab -e
    Then make your entry. My script in this example is located in the root of 'root's' directory. I've also got the script running at 03:00.

    Code:
    0 3 * * * /root/sa-updater &> /dev/null
    If you don't want the emails sent to you daily then just use the following crontab statement.

    Code:
    0 3 * * * /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update &> /dev/null
    That should be about it.:eek:

    Hope this is helpful. I'm running this with Ubuntu 6.06 (PPC and x86) I'd like feedback on how this performs in other environments.
     
  2. edge

    edge Active Member Moderator

    Nice one!

    I'll give it a go on one of my servers that does still get a lot of spam
     
  3. martinfst

    martinfst ISPConfig Developer ISPConfig Developer

    Seems to run nicely. You have to change the permission though to make it executable:
    Code:
    chmod 750 /root/sa-updater
    . I'll see if it catches more spam now.

    Edit: I'm running Ubuntu Edge Eft 6.10
     
    Last edited: Feb 19, 2007
  4. bluethunder82

    bluethunder82 Member

    I have found that running the update rules helps clean up the last bit of spam I get. The other prevention I use is zen.spamhaus.org. SPAM still gets through but nothing that has anyone commenting.

    Hope you get good results as well.
     
  5. edge

    edge Active Member Moderator

    The script is working nice on my Debian Sarge server.
    I'll add it tomorrow to my other two server.
     
    Last edited: Feb 19, 2007
  6. djtremors

    djtremors ISPConfig Developer ISPConfig Developer

    I just use the rules_du_jour script

    http://sandgnat.com/rdj/rules_du_jour

    you have to tell it where your spamassassin rules folder is which I just do a simple

    PHP:
    ln -/home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin /etc/spamassassin
    and then crontab run

    PHP:
     sh /home/admispconfig/ispconfig/tools/spamassassin/etc/mail/spamassassin/RulesDuJour/rules_du_jour
     
  7. collimic

    collimic New Member

    update errors.

    Hello, I followed the instructions and yet I am getting errors when I try and update.

    error: no mirror data available for channel updates.spamassassin.org
    channel: MIRRORED.BY file location was not in DNS, channel failed

    Any help would be great.
     
  8. falko

    falko Super Moderator ISPConfig Developer

    What happens when you run
    Code:
    /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update
    manually?
     
  9. madmucho

    madmucho ISPConfig Developer ISPConfig Developer

    Nice script

    Thank you for that script i use it on testing server now with some specific changes and works ok :) nice help against spam.

    PS: Mandriva, i know mandriva again, there is stupid change in path ../usr/local/bin/....
     
  10. Hagforce

    Hagforce New Member

    When i run "/home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update" nothing happends.
    Is there supposed to be some sort of confirmation?
    How can I check if the update was made?

    I added "23 4 */2 * * /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/sa-update &> /dev/null" to a file and placed it in /etc/cron.daily would this work for updating?
     
  11. madmucho

    madmucho ISPConfig Developer ISPConfig Developer

    When there is no problem no output is made, if you have &> /dev/null in your crontab line you will never get response from updates, if there will be problem, you will not get message becasuse response is pointed to null..

    if you look in script writen above this topic there is exit value of sa_update function
    if [ $exitcode = 0 ]; then....

    elif [ $exitcode = 1 ]; then...
     
  12. Hagforce

    Hagforce New Member

    Ok, thank you.

    Does SA need restart after update?
    Any way of checking manually that update was successful?
     
  13. bluethunder82

    bluethunder82 Member

    Hi Hagforce,
    I may be wrong but spamassassin does not need to be restarted each time a definition is updated. This is not the case if you use it as a daemon.

    Not sure if I understand your manual checking but if you want to see what the latest definitions are in your version of spamassassin visit:

    HTML:
    /home/admispconfig/ispconfig/tools/spamassassin/usr/var/spamassassin/

    Also, in my original code I tried to get the version of the definitions displayed but never got it to work. That being said the information sent via email regarding the versioning was removed. Currently once a week I get an email telling me if new definitions were downloaded. Otherwise nothing else is done. However, from the operation of my ispconfig server this is sufficient.
     
  14. Hagforce

    Hagforce New Member

    Ok thank you.

    I see that the files have updated, so the script works, thank you.
    But the files in "/home/admispconfig/ispconfig/tools/spamassassin/usr/share/spamassassin" have not updated, is these files not in use?
     
  15. madmucho

    madmucho ISPConfig Developer ISPConfig Developer

    as you can see on this page > sa_update
    this file update spamassasin rules, rules which make unwanted mail spam :)
    spamassasin self need to be recompiled or repackaged in your system when new release is out.
     
  16. mathewhayden

    mathewhayden New Member

    Hello..
    Thank you very much for sharing this information us. It will be really very helpful for everybody including me. It is really useful. I will also try these instructions on my server. If I get any type of problem,I will surely discuss it with you. You have done a great job and keep doing good work.
     

Share This Page