only user inter action is reading the screen and putting in the root/superuser password if it's determined that freshclam needs to be up dated.
everything goes to a log and you need to make a very few changes for your system
in avscan make the changes to what you want scanned
in the connect_time script change the time to your needs and situation (3 hours currently)
the update script should need only the log location changed.
of course rename the scripts, make them executable and place them where you place your scripts normally.
Mine are in /usr/local/bin/ and when there related scripts that call one another they go in their own file
/usr/local/bin/whatever describes them
and change a few parameters to match your system, ask questions and i will help.
I put the lines from the variables that might need changing to fit your needs at the top and made them as obvious as possible. There are very few needing changes.
5 at the top of the variable list for the avscan script
2 at the top of the variable list for the connect_time script
1 at the top of the variable list for the update script
These should be the only "must change" to match your needs
I broke them up into 3 scripts for their function, ease and also for editing. I can make it one big script if anyone wants and also make a menu for several avscan locations where you can pick what to scan.
Last thing I want to do is make a progress bar or something so that the terminal is a bit quieter and not have all the files being scanned rolling by. for now you can let them, use -i to show only infected files or i think -o for no output to screen...with nothing scrolling by it looks like everything froze when it hasn't so i left it to have the scanned files scroll by to show it's running..
Last if anyone has suggestions on how to make the script commands shorter or better let me know.
Main script for scanning
Code: Select all
#!/bin/bash
clear
# Remember to make executable and check permisions
# To scan drives for a virus using ClamAV
# You will need clamav and it's depends installed.
# If you want to make use of any success and or error sounds using ogg or mp3
# I suggest installing mplayer and using it in a script.
# line below will run mplayer in the background avoiding
# mplayers quite verbose output, play the ogg file and close.
#
# Example : use below in a script making needed changes for your system.
#
# mplayer /usr/share/sounds/clam_ogg/Clam-Success.ogg </dev/null >/dev/null 2>&1 &
# change the 5 lines below to match your needs
CONNECT_TIME="$HOME/new_test/connect_test_time" # location of connect script
TARGET="/media/Extra/" # Change to what you want scanned
VIRUS="$HOME/.VIRUS/" # directory you want the virus's moved to
SCAN_LOG="$HOME/ScanLog/Clam.log" # directory you want the scan log placed
HIDE="(hidden directory)" # uncomment if VIRUS is a hidden directory
VERSION="11-07-2014" # used for log
MOVED="Virus has been moved to:"
RIGHT_NOW=$(date "+ %a %x %r")
RIGHT_NOW1=$(date "+ %s")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
NO_DRIVE="Failed to scan: Not plugged in and or mounted?"
YIKES="Yikes drive not plugged in and or mounted : Nothing to scan"
SUBJECT="----------- SCAN REPORT ------------" # Used for log
SUBJECT1="time stamp for script use" # used for log
SUBJECT2="----------- SCAN FAILED -----------" # used for log
VIRUS0="---------- NO VIRUS FOUND ----------" # used for log and print to screen
VIRUSL1="------------- VIRUS FOUND -------------" # used for log
ERRORL2="----------- ERROR FOUND -----------" # used for log
VIRUSP1="----- VIRUS FOUND : CHECK LOG -----" # Print to screen
ERRORP2="----- ERROR FOUND : CHECK LOG -----" # Print to screen
exit=? # Exit status
# uncomment 4 lines below to remove old log
# and time stamp new log
# leave commented to append to log
# Changes will be needed in the connect_time
# script or freshclam will be unable to update
# due to the time check
# REMEMBER TO MAKE NEEDED CHANGES IN CONNECT_TIME SCRIPT IF UNCOMMENTED BELOW
# echo
# echo -e "Removing old log\n"; sleep 3; clear
# rm -f "$HOME/ScanLog/Clam.log" # Junk old logfile.
# echo -e "$SUBJECT1 $RIGHT_NOW1\n" >> $SCAN_LOG # time stamp new log
# REMEMBER TO MAKE NEEDED CHANGES IN CONNECT_TIME SCRIPT IF UNCOMMENTED ABOVE
echo
echo -e "Testing for internet connection and checking time of last update\n"
sleep 4
# use this to test for internet connection and to call freshclam if connected
# if not connected then log: not connected and do the scan anyhow
# Will also check to see how long ago virus database has been updated
# and depending on length of time either allow the update or deny the update
$CONNECT_TIME # calls script that determines if there is a internet
# connection and also how long it has been since the
# virus database has been updated
if [ -d $TARGET ]; then
echo # just a blank line to make reading easier
echo -e "Getting ready to scan $TARGET for viruses\n"
echo -e "If any infected files are found they will be\n"
echo -e "moved to $VIRUS $HIDE\n"
echo -e "Scan Log will be in $SCAN_LOG\n"
echo -e "Scan will begin shortly, be patient $USER\n"
clamscan -r --move=$VIRUS $TARGET -l $SCAN_LOG # clamscan command and arguments/options
if [ "$?" -eq "1" ]; then
echo -e "\n" >> $SCAN_LOG # inserts 2 blank lines in log (for layout and formatting)
echo $VIRUSL1 >> $SCAN_LOG
echo -e "$MOVED\n$VIRUS\n$HIDE\n" >> $SCAN_LOG
echo
echo -e "$VIRUSP1"
elif [ "$?" -gt "1" ]; then
echo -e "\n" >> $SCAN_LOG
echo $ERRORL2 >> $SCAN_LOG
echo
echo -e "$ERRORP2"
else
echo -e "\n" >> $SCAN_LOG
echo -e "$VIRUS0\n" >> $SCAN_LOG
echo
echo -e "$VIRUS0"
fi
echo >> $SCAN_LOG # inserts blank line in log (for layout and formatting)
echo $SUBJECT >> $SCAN_LOG
echo -e "Script: $(basename $0) v$VERSION - for user: $LOGNAME" >> $SCAN_LOG
echo -e "Scanmode: Recursive\nFiles Scanned: $TARGET\n$TIME_STAMP\n" >> $SCAN_LOG
# above logging is used when drive/directory is present
sleep 10; clear
# below is used for log when drive is missing or not mounted
else
echo
echo -e "$YIKES\n"
echo >> $SCAN_LOG # inserts a blank line in log (for layout and formatting)
echo $SUBJECT2 >> $SCAN_LOG
echo -e "Script: $(basename $0) v$VERSION - for user: $LOGNAME" >> $SCAN_LOG
echo -e "Missing target $TARGET\n$NO_DRIVE\n$TIME_STAMP\n" >> $SCAN_LOG
sleep 4; clear
fi
exit
done
Script for Internet connection and or time based updating
Code: Select all
#!/bin/bash
clear
# change the 2 lines below to match your needs
VIRUS_UPDATE="/home/Greg/new_test/update_test" # this calls freshclam from another script
SCAN_LOG="$HOME/ScanLog/Clam.log" # directory the log is placed in
VERSION="11-07-2014"
exit=?
BLANK="-------------------------------------------------------------------------------"
RIGHT_NOW1=$(date "+ %s")
RIGHT_NOW=$(date "+ %a %x %r")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
SUBJECT1="time stamp for script use"
SUBJECT2="Something went wrong (exit code greater than 2)"
INT_TIME="Connected and Stamp found"
INT_TIME1="update more than"
INT_TIME2="update less than"
WAIT_TIME="3 Hours ago"
SECONDS="10800" # 3600 seconds per hour, 10,800 seconds in 3 hours
# this is where you can change your time interval
# for virus database updating, change the red number
# in seconds to what you need or prefer,
# currently it is 3 hours or 10,800 seconds
# Changes need to be in seconds
wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null
if [ "$?" -eq "0" ]; then
echo
echo -e "Checking for Clam.log time stamp\n"
sleep 4; clear
if grep -q "$SUBJECT1" "$SCAN_LOG"; then
echo
echo -e "Clam.Log is time stamped\n"
sleep 4; clear
else
echo -e "$SUBJECT1 $RIGHT_NOW1\n" >> $SCAN_LOG
echo
echo -e "Time stamp is missing : Adding current time stamp\n"
echo -e "Virus database will not be updated at this time\n"
sleep 6; clear
fi
# pulls the update time from the Clam.log in seconds
# 3600 seconds per hour, 10,800 seconds in 3 hours
log_time=$(tac $SCAN_LOG | grep -m 1 "$SUBJECT1" | awk '{print $NF}')
# Pulls system time in seconds
sys_time=$(date "+%s" | awk '{print $NF}')
# determines if virus database needs updating according
# to internet connection and time stamp in Clam.log
test $(($sys_time-$log_time)) -gt "$SECONDS"
if [ "$?" -eq "0" ]; then
clear
echo
echo -e "$INT_TIME\n$INT_TIME1 $WAIT_TIME\nupdating virus database before scan\n"
#echo -e "$INT_TIME\n"
#echo -e "more than $WAIT_TIME updating virus database before scan\n"
echo -e "Wait just a moment for update to start $USER\n"
echo >> $SCAN_LOG
echo -e "$BLANK\n\n" >> $SCAN_LOG
echo -e "-------- Internet Connected --------\n" >> $SCAN_LOG
echo -e "$RIGHT_NOW" >> $SCAN_LOG
echo -e "$INT_TIME\n$INT_TIME1 $WAIT_TIME" >> $SCAN_LOG
#echo -e "$INT_TIME\n" >> SCAN_LOG
#echo -e "more than $WAIT_TIME" >> $SCAN_LOG
echo -e "Virus database updated before scan" >> $SCAN_LOG
echo -e "$SUBJECT1 $RIGHT_NOW1\n" >> $SCAN_LOG
sleep 8; clear
$VIRUS_UPDATE # calls script to start freshclam
# to update the virus database
elif [ "$?" -eq "1" ]; then
echo
echo -e "$INT_TIME\n$INT_TIME2 $WAIT_TIME\nnot updating virus database before scan\n"
#echo -e "$INT_TIME\n"
#echo -e "less than $WAIT_TIME not updating virus database before scan\n"
echo -e "Wait just a moment for scan to start $USER\n"
echo >> $SCAN_LOG
echo -e "$BLANK\n\n" >> $SCAN_LOG
echo -e "------ Internet Connected --------\n" >> $SCAN_LOG
echo -e "$RIGHT_NOW" >> $SCAN_LOG
echo -e "$INT_TIME\n$INT_TIME2 $WAIT_TIME" >> $SCAN_LOG
#echo -e "less than $WAIT_TIME" >> $SCAN_LOG
echo -e "WILL NOT UPDATE VIRUS DATABASE" >> $SCAN_LOG
echo -e "$SUBJECT1 $RIGHT_NOW1\n" >> $SCAN_LOG
sleep 10; clear
else
echo -e "$SUBJECT2"
sleep 4; clear
fi
else
echo
echo -e "Internet disconnected running scan without updating virus database\n"
echo -e "Wait just a moment for scan to start $USER\n"
echo >> $SCAN_LOG
echo -e "$BLANK\n\n" >> $SCAN_LOG
echo -e "------ Internet disconnected ------\n" >> $SCAN_LOG
echo -e "running scan without updating virus database\n" >> $SCAN_LOG
sleep 6; clear
fi
exit
the script to call freshclam and do the actual updating
Code: Select all
#!/bin/bash
# Script has to be run as root/superuser
# This Script is to be used to update virus data base
# place script in /usr/local/bin and make executable or
# anywhere in your path where you place your scripts
# you will have to make changes in the script if other than /usr/local/bin
# This is to check if your root/superuser and if not prompts you for root's password
if [ $(id -u) != "0" ]; then
echo
echo -e " You must be root/superuser to run this script $USER\n" >&2
# su -c '' will give a root password prompt for this sesion and then close root when you quit the script
su -c /usr/bin/freshclam
clear
# Change to match Clam.log location
SCAN_LOG="$HOME/ScanLog/Clam.log" # directory the log is placed in
VERSION="11-07-2014" # Used for log
BLANK="-------------------------------------------------------------------------------"
RIGHT_NOW=$(date "+ %a %x %r")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
SUBJECT="-------- VIRUS UPDATE REPORT --------" # Used for log
SUBJECT2="Virus database has been updated and is current"
LOG_UPDATE="Log has been updated to show database is current"
echo >> $SCAN_LOG # inserts blank line in log (for layout and formatting)
echo -e "$BLANK\n\n" >> $SCAN_LOG
echo $SUBJECT >> $SCAN_LOG
echo -e "Script: $(basename $0) v$VERSION - for user: $LOGNAME" >> $SCAN_LOG
echo -e "$SUBJECT2\n$TIME_STAMP\n" >> $SCAN_LOG
echo
echo -e "$LOG_UPDATE\n"
sleep 6; clear
fi
exit