bashscripts/scan_clam.sh

33 lines
970 B
Bash

#!/bin/bash
LOGDIR="/var/log/clamav/scan/";
LOGFILE="clamav-$(date +'%Y-%m-%d').log";
DIRTOSCAN="/path/to/folder/to/scan"; #multiple folders separate by space
readonly TOKEN="<TOKEN_GOTIFY_APP>";
LOG_PRESERVE_DAYS=30;
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
sh ./gotifypush.sh "CLAMAV Scan Kerodes Studi7" "Scanned folder: **$S** \r $MALWARE" 5 $TOKEN
else
echo "[clamav] No infected files found."
fi
done
#clean old logs files
find $LOGDIR -maxdepth 1 -mtime +$LOG_PRESERVE_DAYS -exec "rm" -R {} \;
exit 0