#!/bin/bash
# avscan.sh
# Andrew Crawford <Andrew@Evermore.com>
# Scans a target directory and children using clamscan, reporting back
# only if infected files or other problems are found
#
# Add to crontab:
# 32 0 * * * /usr/local/bin/avscan.sh > /dev/null 2>&1
#A temporary file
FILE=/tmp/clamscan_result.txt
# A list of users to be notified
RECIPIENTS='admin@evermore.com'
#The subject for the email
SUBJECT="SERVERNAME Virus Scanning Results"
#the FROM address for the notification email
SENDER="admin@evermore.com"
#IP address of the mail server
MAILSERVER="127.0.0.1"
# The scan target
SCANTARGET="/home"
# first, update the virus defs
/usr/bin/freshclam
# run the scan
/usr/bin/clamscan -r -i --quiet --log=$FILE $SCANTARGET
# were there any problems?
if (($? > 0)) ; then
# Found a problem
# Send an email listing these results to the receipients
for TO in $RECIPIENTS; do
#Set the smtp variable to the value of MAILSERVER
# so that the mail program will
# send the outgoing mail server to the smtp server for delivery.
smtp=$MAILSERVER from=$SENDER mail -s "$SUBJECT - $DATE" $FROM $TO < $FILE
done
fi
#clean up the temporary files so we don't leave em all laying around.
rm $FILE
exit