Checking for new clamav version for SuSE linux
Due to my use of an "old" version of SuSE I can't just get the latest version of clamav (anti-virus software for linux), but the folks at SuSE have a site that is updated with newer versions. Rather than checking each day to see if they have a newer version than me, I wrote this:
#!/bin/sh
#
# by Michael Mayer-Oakes
# 6/13/2009
# get the latest version for clamav from ftp.suse.com
LOGNAME="/var/log/your.log.name.log" # change this
HEADER="Suse Projects Clamav Check"
AWK=`which awk` || AWK="/usr/bin/awk"
SED=`which sed` || SED="/usr/bin/sed"
LOGGER=`which logger` || LOGGER="/usr/bin/logger"
ECHO=`which echo` || ECHO="/bin/echo"
DATE=`which date` || DATE="/bin/date"
NAIL=`which nail` || NAIL="/usr/bin/nail"
CLAMD=`which clamd` || CLAMD="/usr/sbin/clamd"
# get current version of clamav, to check against available ones
MYVERSION=`$CLAMD -V | $AWK '{print $2}' | $SED 's/\// /g' | $AWK '{print $1}'`
$LOGGER -t $0[$$] Start $HEADER
$ECHO " " >> $LOGNAME
$ECHO "Start $HEADER" >> $LOGNAME
$DATE >> $LOGNAME
# set to script working directory
cd "/path/to/script"
# get the latest listing
cat projectsclamavinput | ftp -a > projectsclamavoutput
# get list of all directories, each should be a version of clamav
FILELIST="`grep 'clamav' projectsclamavoutput | awk '// {print $9}' | sed '/clamav-/s///'`"
$ECHO "Got list of versions from Suse" >> $LOGNAME
$DATE >> $LOGNAME
for FILE in $FILELIST
do
$ECHO "version "$FILE" found" >> $LOGNAME
FILEVERSIONINT=`echo $FILE | sed '/\./s//0/g'`
MYVERSIONINT=`echo $MYVERSION | sed '/\./s//0/g'`
# testing MYVERSIONINT="0095"
# TODO
# more testing here, when version 0.96 comes out this won't work
if [ $FILEVERSIONINT -gt $MYVERSIONINT ];
then
$ECHO "version "$FILE" is newer than current version "$MYVERSION >> $LOGNAME
DIRECTORYLIST=`echo 'clamav-'$FILE`
fi
done
if [ $DIRECTORYLIST ]; then
# send email
$ECHO "Version "$DIRECTORYLIST | $NAIL -r fromaddress@yourdomain.com -s "NEW clamav found" toaddress@yourdomain.com
# build the FTP GET file
echo "open ftp.suse.com" > projectclamavget
# i have an Intel 32 bit CPU, version 9 SuSE, "sles9-i386"
echo "cd pub/projects/clamav/"$DIRECTORYLIST"/sles9-i386" >> projectclamavget
# change this to your path
echo "lcd /path/to/save/clamav/" >> projectclamavget
echo "bin" >> projectclamavget
echo "prompt" >> projectclamavget
echo "mget *" >> projectclamavget
echo "quit" >> projectclamavget
$ECHO "Created Clamav Version To Get From Suse "$DIRECTORYLIST >> $LOGNAME
$DATE >> $LOGNAME
# get the files, listed above
cat projectclamavget | ftp -a > projectclamavgetoutput
fi
$DATE >> $LOGNAME
$ECHO "End $HEADER" >> $LOGNAME
$LOGGER -t $0[$$] End $HEADER
# end of script
Along with this projectsclamavinput file
open ftp.suse.com
cd pub/projects/clamav
ls -l
quit
And last but not least a cron entry, something like this
0 1 * * * /path/to/script/clamav.pl
Now you are ready to go and keep up with the new versions of clamav. Heck, one could even install the new version after it was downloaded...