Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to automate clamav package updates UNIX
ClamAV is an open source antivirus product. You can update the virus definitions by running the command freshclam in Terminal. The only shortcoming of the packages is that when the clamav package itself is updated, you have to surf to the sourceforge site, download the latest tarball, compile it and install it.

This shell script automates all of this:

#!/bin/sh
############################################
## Documentation:
## This script downloads the latest version of clamav and installs
## it. I've used the download mirror in Phoenix Arizona. You should
## modify the url variable to the mirror closest to you.
############################################
url="http://easynews.dl.sourceforge.net/sourceforge/clamav/clamav-"
latest=`lynx -dump "http://www.clamav.net/stable.php#pagestart" \
| grep "   clamav" | awk '{print $2}' | head -1`
wget $url$latest.tar.gz && \
printf "The latest version of clamav or %s has been downloaded!\n" $latest && \
tar zxvf clamav-$latest.tar.gz && \
cd clamav-$latest
./configure &&
make && \
sudo make install && \
printf "Ok I am updating to the latest virus definitions for \
version %s by running freshclam.", $latest && \
freshclam && \
cd ..
rm -rf cd clamav-$latest

[robg adds: I haven't tested this one -- there's also a GUI version of ClamAV for OS X called ClamXav, if you'd like to try it out without the command line work.]
    •    
  • Currently 2.67 / 5
  You rated: 5 / 5 (3 votes cast)
 
[17,634 views]  

A script to automate clamav package updates | 12 comments | Create New Account
Click here to return to the 'A script to automate clamav package updates' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to automate clamav package updates
Authored by: foilpan on Apr 14, '06 08:55:23AM
this will work if users have wget installed, but it's not by default. use curl instead, like so:
curl -O <url>
that should work for any standard OS X install. thanks for the tip!

[ Reply to This | # ]
A script to automate clamav package updates
Authored by: smkolins on Apr 15, '06 09:01:51PM

ran the script in terminal and...
... command substitution: line 2: syntax error near unexpected token `|'
... command substitution: line 2: `| grep " clamav" | awk '{print $2}' | head -1'
... line 1: lynx: command not found
... line 11: syntax error near unexpected token `&'
... line 11: `curl -O <url>$latest.tar.gz && &#092;'

I don't think I know enough about scripting to fix this...

---
Possess a pure, kindly, and radiant heart!



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: pub3abn on Apr 14, '06 09:48:24AM

Unfortunately, following this hint means that you will no longer be a potential virus vector for your hapless Windows colleagues. What's the fun in that?

(Of course you may want to do this for the sake of your Boot Camp, Parallels, Virtual PC buddies.)



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: exu on Apr 14, '06 10:10:40AM

Fink keeps their package updated pretty well. I use finks on x server (intstead of dealing with apple's installed version) in conjunction with surgemail.



[ Reply to This | # ]
fink
Authored by: macubergeek on Apr 14, '06 03:25:44PM

Actually I've had problems with fink lagging behind in keeping clamav up to date. I'll give it a second look though. Thanks!



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: Zeitkind on Apr 15, '06 04:38:18AM

Why not use freshclam? It's the default app to update clamav-databases.



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: taubman on Apr 15, '06 08:32:20AM

The script updates the program, not the database



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: Zeitkind on Apr 23, '06 03:19:59AM

This is wrong. Freshclam updates the databases by using the pool-servers. Critical network servers should run freshclam directly against the clamav mirrors as daemon or daily cron. Virus definition updates are not available for older versions of clamav, so you must keep your client up-to-date.



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: smkolins on Apr 15, '06 08:49:03PM

To keep compatibility with ClamXav just change ./configure to ./configure --prefix=/usr/local/clamXav
...

---
Possess a pure, kindly, and radiant heart!



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: edbolson on Apr 16, '06 09:31:26PM
I don't have lynx installed, but this code appeared to work (at least once) in place of the lynx call:

latest=`wget "http://www.clamav.net/stable.php#pagestart" \
; grep " released (" stable.php | awk '{print $2}' | head -1`                                                                  


[ Reply to This | # ]
A script to automate clamav package updates
Authored by: smkolins on May 03, '06 01:57:16PM

Here's what I've put together based on the above comments.... Note if you are starting fresh you need to install ClamXav first. And if you are on intel there is partial support - a universal binary is in the works for the ClamXav shell itself. Of course clamav will be built per your hardware. Anyone know how to make the command lines compilation a universal binary??


#!/bin/sh
############################################
## Documentation:
## This script downloads the latest version of clamav and installs
## it compatibly with ClamXav based on work here
## http://www.macosxhints.com/article.php?
## <linewrapped>story=20060409060940665&query=clam
## My example uses a download from the east coast - see
## http://prdownloads.sourceforge.net/clamav/ clamav-0.88.2.tar.gz?
##<linewrapped>download
## for an example of the possible downloads as of version 0.88.2
## note the download urls are not displayed but check the path of the
## actual download
## most of my comments follow the line of code
## I document for learning as well as documenting purposes
## the next thing this should do I think is hide all the text flying by,
## report success or not
## and be included as a program or plugin to clamXav
## note this only updates the engine. An installation of ClamXav will do
## other things
## and should be done BEFORE doing this update.
############################################
url=" http://superb-east.dl.sourceforge.net/sourceforge/clamav/clamav-"
# this is a variable which has most of the download url, it's missing the
# version number
# the following line downloads a url as a file in the default location and it will have the latest version in the html of the file downloaded
latest=`curl -O "http://www.clamav.net/stable.php#pagestart" \
; grep "released (" stable.php* | awk '{print $2}' | head -1`
# this line searches the file named stable.php{anything} for "released ("
# and backs up to the version number in this line of text
curl -O $url$latest.tar.gz && \
# this downloads the resulting file name as a file of the same name
printf "The latest version of clamav or %s has been downloaded!\n" $latest && \
tar zxvf clamav-$latest.tar.gz && \
cd clamav-$latest
./configure --prefix=/usr/local/clamXav &&
# this tells the compiler to install the comilation in the clamXav compatible location
make && \
sudo make install && \
printf "Ok I am updating to the latest virus definitions for \
version %s by running freshclam.", $latest && \
# the following lines reset permissions as needed by clamXav as
# documented at
# http://markallan.co.uk/clamXav/index.php?page=byo
chown -R root /usr/local/clamXav
chgrp -R admin /usr/local/clamXav
chmod -R 666 /usr/local/clamXav/etc/freshclam.conf
chmod u+s /usr/local/clamXav/bin/freshclam
chmod a+wr /usr/local/clamXav/share/clamav/freshclam.log
chown -R clamav /usr/local/clamXav/share/clamav
chgrp -R clamav /usr/local/clamXav/share/clamav
chmod -R g+w /usr/local/clamXav/share/clamav
chmod -R u+w /usr/local/clamXav/share/clamav
/usr/local/clamXav/bin/freshclam && \
# these steps clean up all the stuff downloaded and or created
# to get the work done
cd ..
rm -Rf cd clamav-$latest
rm -f clamav-$latest.tar.gz
rm -f stable.php*

---
Possess a pure, kindly, and radiant heart!



[ Reply to This | # ]
A script to automate clamav package updates
Authored by: smkolins on May 03, '06 02:12:18PM

sorry - thought I had it licked but this one actually finishes...

#!/bin/sh
############################################
## Documentation:
## This script downloads the latest version of clamav and installs
## it compatibly with ClamXav based on work here http://www.macosxhints.com/article.php?
##<linewrapped>story=20060409060940665&query=clam
## My example uses a download from the east coast - see
## http://prdownloads.sourceforge.net/clamav/ clamav-0.88.2.tar.gz?download
## for an example of the possible downloads as of version 0.88.2
## note the download urls are not displayed but check the path of the actual download
## most of my comments follow the line of code
## I document for learning as well as documenting purposes
## the next thing this should do I think is hide all the text flying by,
## report success or not
## and be included as a program or plugin to clamXav
## note this only updates the engine. An installation of ClamXav will do other things
## and should be done BEFORE doing this update.
############################################
url=" http://superb-east.dl.sourceforge.net/sourceforge/clamav/clamav-"
# this is a variable which has most of the download url, it's missing the
# version number
# the following line downloads a url as a file in the default location and it will have the latest version in the html of the file
#<linewrapped>downloaded
latest=`curl -O "http://www.clamav.net/stable.php#pagestart" \
; grep "released (" stable.php* | awk '{print $2}' | head -1`
# this line searches the file named stable.php{anything} for "released ("
# and backs up to the version number in this line of text
curl -O $url$latest.tar.gz && \
# this downloads the resulting file name as a file of the same name
printf "The latest version of clamav or %s has been downloaded!\n" $latest && \
tar zxvf clamav-$latest.tar.gz && \
cd clamav-$latest
./configure --prefix=/usr/local/clamXav &&
# this tells the compiler to install the comilation in the clamXav compatible location
make && \
sudo make install && \
# the following lines reset permissions as needed by clamXav as documented at
# http://markallan.co.uk/clamXav/index.php?page=byo
chown -R root /usr/local/clamXav
chgrp -R admin /usr/local/clamXav
chmod -R 666 /usr/local/clamXav/etc/freshclam.conf
chmod u+s /usr/local/clamXav/bin/freshclam
chmod a+wr /usr/local/clamXav/share/clamav/freshclam.log
chown -R clamav /usr/local/clamXav/share/clamav
chgrp -R clamav /usr/local/clamXav/share/clamav
chmod -R g+w /usr/local/clamXav/share/clamav
chmod -R u+w /usr/local/clamXav/share/clamav
printf "Ok I am updating to the latest virus definitions for \
version %s by running freshclam.", $latest && \
/usr/local/clamXav/bin/freshclam && \
# these steps clean up all the stuff downloaded and or created
cd ..
rm -Rf cd clamav-$latest
rm -f clamav-$latest.tar.gz
rm -f stable.php*

---
Possess a pure, kindly, and radiant heart!



[ Reply to This | # ]