added scripts archive

This commit is contained in:
Oliver Ladner 2014-01-10 10:39:21 +01:00
commit 3a6c57a049

59
archive/virusscan.sh Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# Scans NAS for viruses and alerts users
# Uses avira and clamav ATM
USERS="foo@example.org"
SCANDIR="/mnt/nas_movies /mnt/nas_music /mnt/nas_p2p /mnt/nas_software /mnt/nas_upload"
LOGFILE="/root/virus_scan_$(date +%d_%m_%Y).log"
SCANNER=( "avscan -s --batch --log-file=$LOGFILE $SCANDIR"
"clamscan -r -i -l $LOGFILE $SCANDIR"
)
LOGGER=$(which logger)
for i in $(seq 1 $(echo ${#SCANNER[*]})); do
LOG_NAME="$(basename $0)_$i_$(date +%d_%m_%Y)_XXXXXX"
mktemp -t $LOG_NAME
done
# Logging
function logit() {
case $2 in
error)
$LOGGER -si $(basename $0): $1
;;
*)
$LOGGER -i $(basename $0): $1
;;
esac
}
# Mount all noauto things from /etc/fstab
for i in $(grep 'nfs.*noauto' /etc/fstab | awk '{print $2}'); do
if ! mount $i 2>/dev/null; then logit "Failed mounting $i" "error"; fi
done
# Run all scanners
COUNTER=0
for foo in "${SCANNER[@]}"; do
TEMPFILE=$(find /tmp -type f -name $LOG_NAME)
echo "**********************" > $TEMPFILE
echo "* $COUNTER. scanner running with: $foo" >> $TEMPFILE
echo "**********************" >> $TEMPFILE
$foo
sleep 2
done
# Merge all temporary logfiles
cat /root/avscan.log /root/clamscan.log > $LOGFILE
# Send e-mail
mail -s "NAS antivirus check" $USERS < $LOGFILE
# Unmount all noauto things from /etc/fstab
sleep 3
for i in $(grep 'nfs.*noauto' /etc/fstab | awk '{print $2}'); do
if ! umount $i 2>/dev/null; then logit "Failed unmounting $i" "error"; fi
done