Here is a little script that will cover most of the bases.
Play around with it. I've only ever run it on my system so maybe it wont 
work for you. Takes about an hour on my system to run "both". 

#!/bin/sh

##############################################################################
#                                                                            
#
# function: virus_scan                                                       
#
#           Execute clamav's virus scanner on either or both of the 
system's #
#           binary or library directories.                                   
#
#                                                                            
#
#           Local mail will be sent to "root" upon error or virus found 
and  #
#           the log of the result will be mailed to "root" upon 
completion.  #
#                                                                            
#
#           $PATH is used to locate system binaries.                         
#
#           ldconfig is used to locate system libraries.                     
#
#                                                                            
#
##############################################################################

virus_scan()
{

   local TEMPLOG="/tmp/virusscan.log"
   local CLAMCOMAND
   local DIR

   # check for a running daemon
   if [ "`ps -eo comm|grep clamd`" = "clamd" ]; then
       CLAMCOMAND="clamdscan"
   else
       CLAMCOMAND="clamscan -r"
   fi

   # Scan directories passed to the function
   for DIR in "$@"
      do   
         echo "Scanning $DIR for viruses"
         $CLAMCOMAND $DIR >> $TEMPLOG 2>&1 
         case "$?" in
            '1')
                echo "VIRUS FOUND!! on `date`." | \
                     mail -s "clamav VIRUS FOUND on `date`" root
                ;;
            '2')
                echo "A Process error occured during clamav virus scan 
on `date`." | \
                      mail -s "clamav process error" root
                ;;
             *)
                ;;
         esac
     done

   echo "clamav virus scan result for `date`. See attached log." | \
        mail -s "clamav virus scan log for `date`." -a $TEMPLOG root

   rm $TEMPLOG > /dev/null 2>&1

}

###############################################################################
#                                                                             
#
# function: main                                                              
#
#           Execute clamav's virus scanner on system directories.             
#
#                                                                             
#
# usage:    virusscan { path | lib | both }                                   
#
#                                                                             
#
###############################################################################

case "$1" in
   "path")
      virus_scan `echo $PATH | tr ':' ' '`
      ;;
   "lib")
      virus_scan `ldconfig -vNX | grep '^/.*:$' | awk -F: '{print $1}' | 
tr '\n' ' '` 
      ;;
   "both")
      virus_scan `echo $PATH | tr ':' ' '`
      virus_scan `ldconfig -vNX | grep '^/.*:$' | awk -F: '{print $1}' | 
tr '\n' ' '` 
      ;;
   *)
      echo "usage: virusscan {path | lib | both}"
      ;;
esac

unset virus_scan

# End source ./virusscan

Shawn
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html

Reply via email to