bashscripts/scan_clam.sh

45 lines
1.4 KiB
Bash

#!/bin/bash
# variables
LOGFILE="$(hostname)_clamav-$(date +'%Y-%m-%d').log";
GOTIFY_MESSAGE="Scan init: **"`date +"%d/%m/%Y %H:%M:%S"`"** \r"
LOGS_RELATIVE_PATH="security/"
MALWARE_FOUND=false
readonly TOKEN="<TOKEN_GOTIFY_APP>";
mkdir -p $E7S_CLAM_LOGPATH
for S in ${E7S_CLAM_DIRSTOSCAN}; 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" >> "$E7S_CLAM_LOGPATH$LOGFILE";
echo "Scanned folder: "$S >> "$E7S_CLAM_LOGPATH$LOGFILE";
# get the value of "Infected lines"
MALWARE=$(tail "$E7S_CLAM_LOGPATH$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 "$E7S_CLAM_LOGPATH$LOGFILE" $LOGS_RELATIVE_PATH)
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 $E7S_CLAM_LOGPATH -maxdepth 1 -mtime +$E7S_LOGS_PRESERVE_DAYS -exec "rm" -R {} \;
exit 0