egscripts/egvscan/egvscan

78 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
#
# egvscan
#
# (c) 2007 Egressive Limited
# Virus scan of server storage using clamav
# by rob@egressive.com 20070514
#
##
# Description - egvscan:
#
#
##
#
# Default Settings
#
DEBUG=false
#
if [ $DEBUG == "true" ] ; then
echo "Default Settings"
fi
#
# config file
CONF_FILE=/etc/egscripts/egvscan/egvscan.conf
# logfile
LOGFILE=/var/log/egvscan.log # use logrotate to manage logs
TMP_LOGFILE=/tmp/egvscan.$$
#
# Output by clamAV to indicate it has found a virus
VIRUS_FOUND_WORD="FOUND$"
#
VSCAN_COMMAND=`which clamdscan`
MAIL_COMMAND=`which mail`
GREP_COMMAND=`which grep`
TAIL_COMMAND=`which tail`
NICE_COMMAND=`which nice`
HEAD_COMMAND=`which head`
CAT_COMMAND=`which cat`
DATE_COMMAND=`which date`
FIND_COMMAND=`which find`
#
DATE=`$DATE_COMMAND`
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
echo " Started virus scan ($DATE) " >> $LOGFILE
#
# initialise end status
VSCAN_STATUS="[NO VIRUS DETECTED]"
#
# Get local configuration
#
if [ $DEBUG == "true" ] ; then
echo "Get Local Settings"
fi
if [ -x /etc/egscripts/egvscan/egvscan.conf ] ; then
. $CONF_FILE
else
$CAT_COMMAND $LOGFILE | $MAIL_COMMAND -s "[ERROR] Could not find config file for $SERVERNAME backup" $MAIL_TO
exit 1
fi
#
##
echo " Scanning $i" >> $LOGFILE
$NICE_COMMAND $VSCAN_COMMAND $VSCAN_ARGS -l $TMP_LOGFILE $SCAN_DIR 2>> $LOGFILE
#
if $GREP_COMMAND -c $VIRUS_FOUND_WORD $TMP_LOGFILE
then
$MAIL_COMMAND -s "[VIRUS DETECTED] on $SERVERNAME in a recently created or modified file" $MAIL_TO < $TMP_LOGFILE
fi
if [ -f $TMP_LOGFILE ]
then
cat $TMP_LOGFILE >> $LOGFILE
rm $TMP_LOGFILE
fi
DATE=`$DATE_COMMAND`
echo " Completed virus scan ($DATE) " >> $LOGFILE
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
echo "" >> $LOGFILE