Created
November 19, 2023 06:39
-
-
Save mdutt247/38d6dbd8184d0b66cb55f571fdb19163 to your computer and use it in GitHub Desktop.
Clamav daily scan
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
| #!/usr/bin/env bash | |
| # Author: M. Dutt (hello@mditech.net) | |
| # Date: 19/11/2023 | |
| # Purpose: Clamav daily scan. | |
| # | |
| # chmod +x /path/to/script/clamscan_daily.sh | |
| # | |
| # 01 * * * * /path/to/script/clamscan_daily.sh | |
| # | |
| SUBJECT="`hostname` PASSED DAILY SCAN" | |
| EMAIL="email@example.com" | |
| LOG=/var/log/clamav/clamav.log | |
| TMP_LOG=/tmp/clam.daily | |
| av_report() { | |
| if [ `cat ${TMP_LOG} | grep Infected | grep -v 0 | wc -l` != 0 ] | |
| then | |
| SUBJECT="[WARNING] `hostname` PASSED DAILY SCAN" | |
| fi | |
| EMAILMESSAGE=`mktemp /tmp/virus-alert.XXXXX` | |
| echo "To: ${EMAIL}" >> ${EMAILMESSAGE} | |
| echo "From: root@server.com" >> ${EMAILMESSAGE} | |
| echo "Subject: ${SUBJECT}" >> ${EMAILMESSAGE} | |
| echo "Importance: High" >> ${EMAILMESSAGE} | |
| echo "X-Priority: 1" >> ${EMAILMESSAGE} | |
| echo "`tail -n 50 ${TMP_LOG}`" >> ${EMAILMESSAGE} | |
| sendmail -t < ${EMAILMESSAGE} | |
| cat ${TMP_LOG} >> ${LOG} | |
| rm -rf ${TMP_LOG} | |
| } | |
| av_scan() { | |
| touch ${TMP_LOG} | |
| clamscan -r / --exclude-dir=/sys/ --quiet --infected --log=${TMP_LOG} | |
| } | |
| av_scan | |
| av_report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment