From 3a6c57a049527b943bc55a535dd5fc95a19f71fc Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Fri, 10 Jan 2014 10:39:21 +0100 Subject: [PATCH] added scripts archive --- archive/virusscan.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 archive/virusscan.sh diff --git a/archive/virusscan.sh b/archive/virusscan.sh new file mode 100755 index 0000000..f058610 --- /dev/null +++ b/archive/virusscan.sh @@ -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