bashscripts/scan_clam.sh

33 lines
970 B
Bash
Raw Normal View History

2022-09-29 12:27:20 +02:00
#!/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
2023-01-21 01:18:34 +01:00
sh ./gotifypush.sh "CLAMAV Scan Kerodes Studi7" "Scanned folder: **$S** \r $MALWARE" 5 $TOKEN
2022-09-29 12:27:20 +02:00
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