#!/bin/bash
# Filename: scan.sh
# Version: 230411
# Author: robz
# $HOME scanner with "ClamAV" run from a virtual terminal with a bash alias.
# Check first if you've any other programs called scan, try "man scan" to see
# if manual pages exist, If ok add the alias to the bottom of your ~/.bashrc
# file, modify so it's path points to your scripts directory location.
# "alias scan="/home/user/users_scripts/scan.sh"" save, do "source ~/.bashrc"
# in a terminal to reload the bash configuration, type "scan" to scan.
# Scanning is done recursively on the directory you are in, terminal wise,
# ie. the $PWD - present working directory.
# If this script is likely to be run logged in as another user you'll need to
# be more specific with the path of the sound files.
export DISPLAY=:0 # Make sounds work.
LOGFILE="/tmp/ClamAV-$(date +%A-%H:%M).log" # Make new logfile.
SOUND1=$HOME/Audio/DingLing.wav # OK sound.
SOUND2=$HOME/Audio/HyprBlip.wav # Warning sound.
echo -e "\n\033[37;1mScanning directory:\033[0m $(pwd)\n"
echo -e "\033[33;1mEnter password to update virus definitions\033[0m"
sudo -k freshclam # Update definitions.
# Scan $PWD, do it nicely! exclude large pre-scanned or encrypted directories
# and, as this runs as user, files not belonging to the user.
nice -n 19 /usr/bin/clamscan -r ${pwd} -l $LOGFILE\
--heuristic-scan-precedence\
--exclude-dir="$HOME/Audio"\
--exclude-dir="$HOME/Music"\
--exclude-dir="$HOME/Pictures"\
--exclude-dir="$HOME/.Private"\
--exclude-dir="$HOME/Video"\
--exclude-dir="$HOME/.ntop"\
--exclude-dir="$HOME/.thumbnails"\
--exclude="$HOME/.Synaptic-markings"\
--exclude="$HOME/.selected_editor"
CLAMSCAN=$? # Get exit status.
if [ "$CLAMSCAN" -eq "1" ]; then
echo -e "\033[31;1m[VIRUS FOUND"\!"]\033[0m"
/usr/bin/canberra-gtk-play --volume=4 -f $SOUND2 &
elif [ "$CLAMSCAN" -gt "1" ]; then
echo -e "Scan found errors...\n"$(grep "Access denied" $LOGFILE) | more
echo -e "\033[34;1m[ERROR $CLAMSCAN]\033[0m"
/usr/bin/canberra-gtk-play --volume=4 -f $SOUND1 &
else echo -e "\033[32;1mNo virus found :)\033[0m"
/usr/bin/canberra-gtk-play --volume=4 -f $SOUND1 &
fi
echo -e "\033[1mFor scan details see logfile at $LOGFILE.\033[0m\n"
No comments:
Post a Comment