bashscripts/scan_clam.sh

47 lines
1.5 KiB
Bash

#!/bin/bash
LOGDIR="/var/log/clamav/scan/";
LOGFILE="kerodes_clamav-$(date +'%Y-%m-%d').log";
#DIRTOSCAN="/home/roger/Públic /home/roger/Baixades/targets"; #multiple folders separate by space
DIRTOSCAN="/home/roger/Baixades/targets"; #multiple folders separate by space
readonly TOKEN="<TOKEN_GOTIFY_APP>";
readonly GOTIFY_SERVER="<GOTIFY_URL_SERVER>"
LOG_PRESERVE_DAYS=30;
GOTIFY_MESSAGE="Scan init: **"`date +"%d/%m/%Y %H:%M:%S"`"** \r"
MALWARE_FOUND=false
mkdir -p $LOGDIR
for S in ${DIRTOSCAN}; do
DIRSIZE=$(du -sh "$S" 2>/dev/null | cut -f1);
echo "Starting a daily scan of "$S" directory. Amount of data to be scanned is "$DIRSIZE".";
clamscan -ri "$S" >> "$LOGDIR$LOGFILE";
echo "Scanned folder: "$S >> "$LOGDIR$LOGFILE";
# get the value of "Infected lines"
MALWARE=$(tail "$LOGDIR$LOGFILE"|grep Infected|cut -d" " -f3);
# if the value is not equal to zero, send an email with the log file attached
if [ "$MALWARE" -ne "0" ];then
GOTIFY_MESSAGE="${GOTIFY_MESSAGE} Found **$MALWARE** infected files into **$S** \r"
MALWARE_FOUND=true
else
echo "[clamav] No infected files found."
fi
done
if $MALWARE_FOUND
then
# send log to logs public archive
LOG_URL=$(sh ./utils/logger.sh "$LOGDIR$LOGFILE")
GOTIFY_MESSAGE="${GOTIFY_MESSAGE} Scan end: **"`date +"%d/%m/%Y %H:%M:%S"`"** \r"
GOTIFY_MESSAGE="${GOTIFY_MESSAGE} [LogFile]($LOG_URL)"
sh ./utils/gotifypush.sh "ClamAV Scan $(hostname)" "$GOTIFY_MESSAGE" 5 $TOKEN
fi
#clean old logs files
find $LOGDIR -maxdepth 1 -mtime +$LOG_PRESERVE_DAYS -exec "rm" -R {} \;
exit 0