Last Updated: February 25, 2016
·
319
· bernardocastro

Linux ClamAv scan scheduling

This is a beautiful scan scheduling linux servers with sending notification e-mail log.

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          ClamAv
# Short-Description: Exec scam clamav.
# Description:       Performs scam with ClamAV and sending e-mail of the result log.
### END INIT INFO

path_log="/path/log/clamscan.log"
path_move_virus="/path/quarentena/"
ignore_dir="/path/quarentena"
path_scan="/home"

email_notify="admin@mail.com"

/usr/bin/clamscan -i -l "$path_log" -r --exclude-dir="$ignone_dir" --move="$path_move_virus" "$path_scan"

### Ckeck log exist, send log by mail
if test -f $path_log
then    
    /usr/bin/mailx -s "ClamAV Scan Title `date +%D`" "$email_notify" < "$path_log"
    echo "Send OK"
    echo "" > "$path_log"
else
    /usr/bin/mail -s "ClamAV Scan Error `date +%D`" "$email_notify"
    echo "Sorry, error send by mail"
fi

Now it is only run by scheduling "cron"