Skip to content

Instantly share code, notes, and snippets.

@matchy256
Last active December 9, 2015 21:59
Show Gist options
  • Save matchy256/4334403 to your computer and use it in GitHub Desktop.
Save matchy256/4334403 to your computer and use it in GitHub Desktop.
ClamAV でシステム全体をスキャンして、問題があったらメールするスクリプト。 除外ディレクトリは /etc/clamscan.exclude ファイルに1行ずつ書いとく。/proc は入れといた方がいい。
#!/bin/bash
MAILTO="root"
PATH=/usr/bin:/bin
# excludeopt setup
excludelist=/etc/clamscan.exclude
if [ -s $excludelist ]; then
for i in `cat $excludelist`
do
if [ $(echo "$i"|grep \/$) ]; then
i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d`
excludeopt="${excludeopt} --exclude-dir=^$i"
else
excludeopt="${excludeopt} --exclude=^$i"
fi
done
fi
# signature update
freshclam 2>&1 > /dev/null
# virus scan
CLAMSCANTMP=`mktemp`
#clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
clamscan --recursive ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
# report mail send
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" $MAILTO
rm -f $CLAMSCANTMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment