i'm getting most of what i need and learning case esac , it's not so bad
if then fi else elif is a cake walk now and nesting is an exercise in indenting and knowing what you need before hand.
grep isn't too bad but awk is killing me
how can I get the out put of something like this into a second script?
Code: Select all
MAIN_TARGET=$(tac $PLACES | grep -m 1 "$SCAN_TARGET_1" | awk '{print $NF}')
separating major functions to their own scripts makes thing a lot easier for me to edit and maintain also .
i kinda stripped most things from the scripts to get them running with a minimum of crud for testing.
this is the text file i store the scan targets in | SCAN_TARGET_1 through _5 that grep finds it's info .
Code: Select all
/media/Storage/NewQbToTransfer/
/media/Storage/
/media/Extra/
/media/TvShows/
Ignore most the variables I need to clean them up still.
Code: Select all
#!/bin/bash
clear
# Remember to make executable and check permissions
# case menu for avscan
#------------------------------ START : VARIABLES -----------------------------#
search_for="time stamp for script use" # search string for time stamp for connect_time
sys_seconds="system time in seconds $(date "+%s")" # search string for sys time for connect_time
CONNECT_TIME="/usr/local/bin/virus_scan/connect_time" # location of connect script
SCAN="/usr/local/bin/virus_scan/avscan_no_menu"
# MENU="/usr/local/bin/virus_scan/menu_no_avscan"
PLACES="/usr/local/bin/virus_scan/places_to_scan" # txt file of places to scan
SCAN_TARGET_1="/media/Storage/" # location to scan
SCAN_TARGET_2="/media/Storage/NewQbToTransfer/" # location to scan
SCAN_TARGET_3="/media/Extra/" # location to scan
SCAN_TARGET_4="/media/TvShows/" # location to scan
SCAN_TARGET_5="" # location to scan
SCAN_TARGET_6="" # location to scan
INFO_1="Will start scan on"
Clam_log="$HOME/ScanLog/Clam.log" # location of Clam.log
MOVED="Virus has been moved to:" # Print to screen
VIRUS="$HOME/.VIRUS/" # directory you want the virus's moved to
HIDE="(hidden directory)" # uncomment if VIRUS is a hidden directory
SCAN_LOG="$HOME/ScanLog/Clam.log" # directory you want the scan log placed
VERSION="11-07-2014" # used for log
RIGHT_NOW=$(date "+ %a %x %r") # used for log
RIGHT_NOW1=$(date "+ %s") # used for log
TIME_STAMP="Updated on $RIGHT_NOW" # used for log
NO_DRIVE="Failed to scan: Not plugged in and or mounted? " # Print to screen
YIKES="Yikes drive not plugged in and or mounted : Nothing to scan" # Print to screen
SUBJECT="----------- SCAN REPORT ------------" # Used for log
SUBJECT1="time stamp for script use" # Used for tac / greg / awk
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
selection=
MAIN_TARGET=
#------------------------------- END : VARIABLES ------------------------------#
#--------------------------------- MENU START ---------------------------------#
# until [ "$selection" = "q | Q" ]; do
until [ "$selection" = "q" ]; do
echo ""
echo -e "What / Where would you like to scan for a Virus / Infection $USER?\n"
echo -e "1 - Scan $SCAN_TARGET_1\n"
echo -e "2 - Scan $SCAN_TARGET_2\n"
echo -e "3 - Scan $SCAN_TARGET_3\n"
echo -e "4 - Scan $SCAN_TARGET_4\n"
# echo -e "q | Q - quit and take no further action | exit program\n"
echo -e "q - quit and take no further action | exit menu\n"
echo -e "waiting on your choice $USER\n"
read selection
echo ""
case $selection in
1 ) clear
MAIN_TARGET=$(tac $PLACES | grep -m 1 "$SCAN_TARGET_1" | awk '{print $NF}')
echo -e "$INFO_1 $MAIN_TARGET $USER\n"
sleep 4; clear; $SCAN ;; ##### $SCAN starts the avscan script, how can I output the #####
##### $TARGET_* to the $MAIN_TARGET in the avscan script? #####
2 ) clear
MAIN_TARGET=$(tac $PLACES | grep -m 1 "$SCAN_TARGET_2" | awk '{print $NF}')
echo -e "$INFO_1 $MAIN_TARGET $USER\n"
sleep 4; clear ;;
3 ) clear
MAIN_TARGET=$(tac $PLACES | grep -m 1 "$SCAN_TARGET_3" | awk '{print $NF}')
echo -e "$INFO_1 $MAIN_TARGET $USER\n"
sleep 4; clear ;;
4 ) clear
MAIN_TARGET=$(tac $PLACES | grep -m 1 "$SCAN_TARGET_4" | awk '{print $NF}')
echo -e "$INFO_1 $MAIN_TARGET $USER\n"
sleep 4; clear ;;
# q | Q ) clear;exit ;;
q) clear; exit ;;
* ) clear; echo; echo -e "INVALID ENTRY : RESTARTING MENU\n"
sleep 2; clear ;;
esac
done
#--------------------------------- MENU END -----------------------------------#
Code: Select all
#!/bin/bash
clear
# Remember to make executable and check permisions
#------------------------------ START : VARIABLES -----------------------------#
search_for="time stamp for script use" # search string for time stamp for connect_time
sys_seconds="system time in seconds $(date "+%s")" # search string for sys time for connect_time
CONNECT_TIME="/usr/local/bin/virus_scan/connect_time" # location of connect script
SCAN="/usr/local/bin/virus_scan/avscan_no_menu"
MENU="/usr/local/bin/virus_scan/menu_no_avscan"
PLACES="/usr/local/bin/virus_scan/places_to_scan"
SCAN_TARGET_1="/media/Storage/" # location to scan
SCAN_TARGET_2="/media/Storage/NewQbToTransfer/" # location to scan
SCAN_TARGET_3="/media/Extra/" # location to scan
SCAN_TARGET_4="/media/TvShows/" # location to scan
SCAN_TARGET_5="" # location to scan
SCAN_TARGET_6="" # location to scan
INFO_1="Will start scan on"
Clam_log="$HOME/ScanLog/Clam.log" # location of Clam.log
MOVED="Virus has been moved to:" # Print to screen
VIRUS="$HOME/.VIRUS/" # directory you want the virus's moved to
HIDE="(hidden directory)" # uncomment if VIRUS is a hidden directory
SCAN_LOG="$HOME/ScanLog/Clam.log" # directory you want the scan log placed
VERSION="11-07-2014" # used for log
RIGHT_NOW=$(date "+ %a %x %r") # used for log
RIGHT_NOW1=$(date "+ %s") # used for log
TIME_STAMP="Updated on $RIGHT_NOW" # used for log
NO_DRIVE="Failed to scan: Not plugged in and or mounted? " # Print to screen
YIKES="Yikes drive not plugged in and or mounted : Nothing to scan" # Print to screen
SUBJECT="----------- SCAN REPORT ------------" # Used for log
SUBJECT1="time stamp for script use" # Used for tac / greg / awk
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
selection=
MAIN_TARGET=
#------------------------------- END : VARIABLES ------------------------------#
# 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 CHAGES IN CONNECT_TIME SCRIPT IF UNCOMMENTED BELOW -#
# echo
# echo -e "Removing old log\n"; sleep 3; clear
# rm -f "$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 -#
#-------------------------- CONNECTION : TIME START ---------------------------#
#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
#-------------------------- CONNECTION : TIME END -----------------------------#
#---------------------------- MAIN PART TO DO SCAN -------------------------------#
if [ -d $MAIN_TARGET -o -f $MAIN_TARGET ]; then
echo # just a blank line to make reading easier
echo -e "Getting ready to scan $MAIN_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 on $MAIN_TARGET, be patient $USER\n"
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: $MAIN_TARGET\n$TIME_STAMP\n" >> $SCAN_LOG
clamscan -r --move=$VIRUS $MAIN_TARGET -l $SCAN_LOG # clamscan command and arguments/options
##### how can i import the $SCAN_TARGET_* info from the menu script?
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
# 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 $MAIN_TARGET\n$NO_DRIVE\n$TIME_STAMP\n" >> $SCAN_LOG
sleep 4; clear
fi
exit
done
what am I missing and just haven't got my mind wrapped around yet?
Any suggestions or a direction to try?