Suggested change to http://www.mailscanner.info/files/4/KAM.cf.sh script

Mark Sapiro mark at msapiro.net
Mon Sep 7 20:31:01 IST 2009


I note the script at http://www.mailscanner.info/files/4/KAM.cf.sh has
been recently changed. The prior script contained

/usr/bin/wget -N -O KAM.cf http://www.peregrinehw.com/downloads/SpamAssassin/contrib/KAM.cf

With my version of wget at least, the -N option was inneffective in
preventing unnecessary retrieval of unchanged data because of the
(unnecessary) -O KAM.cf option.

This has apparently been recognized as the script was changed to do

/usr/bin/wget -O KAM.cf http://www.peregrinehw.com/downloads/SpamAssassin/contrib/KAM.cf

instead, but it also always downloads the file and reloads MailScanner.

I have changed the script somewhat differently, and with my changes,
wget does not retrieve the file if it is unchanged, and only reloads
MailScanner if it does change the file.

Attached is a patch KAM_cf_sh.patch to convert the current
http://www.mailscanner.info/files/4/KAM.cf.sh script, and KAM_cf_sh
is the converted script.

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

-------------- next part --------------
--- KAM.cf.sh	2009-09-07 12:06:03.000000000 -0700
+++ .cron/KAM.cf.sh	2009-09-07 08:08:35.000000000 -0700
@@ -17,23 +17,34 @@
 fi
 
 # JKF Fetch KAM.cf
+reload=1
 echo Fetching KAM.cf...
 cd /etc/mail/spamassassin
-rm -f KAM.cf
-/usr/bin/wget -O KAM.cf http://www.peregrinehw.com/downloads/SpamAssassin/contrib/KAM.cf
+/usr/bin/wget -N http://www.peregrinehw.com/downloads/SpamAssassin/contrib/KAM.cf
 if [ "$?" = "0" ]; then
-    echo It completed and fetched something
-    if ( tail -10 KAM.cf | grep -q '^#.*EOF' ); then
-      echo It succeeded so make a backup
-      cp -f KAM.cf KAM.cf.backup
+    echo It completed OK
+    if [ KAM.cf -nt KAM.cf.backup ]; then
+      if ( tail -10 KAM.cf | grep -q '^#.*EOF' ); then
+        echo It succeeded so make a backup
+        cp -f KAM.cf KAM.cf.backup
+      else
+        echo ERROR: Could not find EOF marker
+        cp -f KAM.cf.backup KAM.cf
+      fi
     else
-      echo ERROR: Could not find EOF marker
-      cp -f KAM.cf.backup KAM.cf
+      echo Remote file not newer than local
+      reload=0
     fi
 else
     echo It failed to complete properly
     cp -f KAM.cf.backup KAM.cf
 fi
-echo Reloading MailScanner and SpamAssassin configuration rules
-/etc/init.d/MailScanner reload
+# Do this here based on switch rather than just putting it in the
+#        echo It succeeded so make a backup
+# block on the remote chance that the file got corrupted and a child
+# was started before we restored the backup.
+if [ reload == 1 ] ; then
+    echo Reloading MailScanner and SpamAssassin configuration rules
+    /etc/init.d/MailScanner reload
+fi
 
-------------- next part --------------
#!/bin/bash

# Insert a random delay up to this value, to spread virus updates round
# the clock. 1800 seconds = 30 minutes.
# Set this to 0 to disable it.
UPDATEMAXDELAY=600
if [ -f /etc/sysconfig/MailScanner ] ; then
        . /etc/sysconfig/MailScanner
fi
export UPDATEMAXDELAY

if [ "x$UPDATEMAXDELAY" = "x0" ]; then
  :
else
  logger -p mail.info -t KAM.cf.sh Delaying cron job up to $UPDATEMAXDELAY seconds
  perl -e "sleep int(rand($UPDATEMAXDELAY));"
fi

# JKF Fetch KAM.cf
reload=1
echo Fetching KAM.cf...
cd /etc/mail/spamassassin
/usr/bin/wget -N http://www.peregrinehw.com/downloads/SpamAssassin/contrib/KAM.cf
if [ "$?" = "0" ]; then
    echo It completed OK
    if [ KAM.cf -nt KAM.cf.backup ]; then
      if ( tail -10 KAM.cf | grep -q '^#.*EOF' ); then
        echo It succeeded so make a backup
        cp -f KAM.cf KAM.cf.backup
      else
        echo ERROR: Could not find EOF marker
        cp -f KAM.cf.backup KAM.cf
      fi
    else
      echo Remote file not newer than local
      reload=0
    fi
else
    echo It failed to complete properly
    cp -f KAM.cf.backup KAM.cf
fi
# Do this here based on switch rather than just putting it in the
#        echo It succeeded so make a backup
# block on the remote chance that the file got corrupted and a child
# was started before we restored the backup.
if [ reload == 1 ] ; then
    echo Reloading MailScanner and SpamAssassin configuration rules
    /etc/init.d/MailScanner reload
fi



More information about the MailScanner mailing list