Created
February 19, 2020 12:35
-
-
Save steffenfritz/5e44500883629e1e4621761dfd6c8e94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| LOGFILE="/var/log/clamav/clamav-$(date +'%Y-%m-%d').log"; | |
| EMAIL_MSG="Please see the log file attached."; | |
| EMAIL_FROM="clamav-daily@example.com"; | |
| EMAIL_TO="username@example.com"; | |
| DIRTOSCAN="/var/www /var/vmail"; | |
| 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" >> "$LOGFILE"; | |
| # get the value of "Infected lines" | |
| MALWARE=$(tail "$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 | |
| # using heirloom-mailx below | |
| echo "$EMAIL_MSG"|mail -a "$LOGFILE" -s "Malware Found" -r "$EMAIL_FROM" "$EMAIL_TO"; | |
| fi | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment