Hello all. I want the scanvirus script to display current top level directory being scanned. To display it like the '-i' option, but add the current top level directory being scanned. I can capture and control what comes out. However, control-c break doesn't work right and I end up with background clamscan that stops unmount.
I need to understand how I could do this. Thanks.
Code:#!/bin/bash #: Title : scanvirus #: Date Created: Thu Sep 2 19:27:00 PST 2010 #: Last Edit : Wed Apr 6 3:00:00 PST 2015 #: Author : Lord Valarian #: Version : 1.1.0 #: Description : Run virus scanning application #: Options : p1: -windows -linux #Open bin folder #Place this file inside "/home/bin/" # #Right-click on scanvirus #Click on properties #Click on permissions #Check executable and click ok # #Click Control -> Tools -> Open Terminal #Enter termal command: scanvirus --setup #Enter admin password, wait for it to finish. Don't close terminal. #Enter termal command: scanvirus --kdeicons #close terminal windows # #Click on either desktop icon to scan Create_KDE_linux_scan_icon() { cat > ScanVirus_KDE_Linux_Scan.desktop <<EOF #!/usr/bin/env xdg-open [Desktop Entry] Comment[en_US]= Comment= Exec=sh scanvirus -linux GenericName[en_US]= GenericName= Icon=kde MimeType= Name[en_US]=ScanVirus - linux anti-virus scan Name=ScanVirus - linux anti-virus scan Path=$PATH StartupNotify=true Terminal=true TerminalOptions=\s--noclose Type=Application X-DBUS-ServiceName= X-DBUS-StartupType= X-KDE-SubstituteUID=false X-KDE-Username= X-SuSE-translate=trueEOF EOF #set file permissions chmod 744 ScanVirus_KDE_Linux_Scan.desktop } Create_KDE_windows_scan_icon() { cat > ScanVirus_KDE_Windows_Scan.desktop <<EOF #!/usr/bin/env xdg-open [Desktop Entry] Comment[en_US]= Comment= Exec=sh scanvirus -mswin GenericName[en_US]= GenericName= Icon=kde MimeType= Name[en_US]=ScanVirus - windows anti-virus scan Name=ScanVirus - windows anti-virus scan Path=$PATH StartupNotify=true Terminal=true TerminalOptions=\s--noclose Type=Application X-DBUS-ServiceName= X-DBUS-StartupType= X-KDE-SubstituteUID=false X-KDE-Username= X-SuSE-translate=true EOF #set file permissions chmod 744 ScanVirus_KDE_Windows_Scan.desktop } #pwd #if [ $1 = "-mswin" -o $1 = "-w" ]; then # read file path line by line and scan # while read line # do # if [ "$line" != "" ]; then # printf "__________________________________________________\n" # printf "scanning %s\n" $line # clamscan $line # printf "__________________________________________________\n" # printf "\n" # fi # done < /home/$USER/bin/$scanvirus_mswin_paths_data #read -p "Done. Press any key..." -n1 -s;printf ""; ##################### # shortcut code for clamscan # ##################### control_c() # run if user hits control-c { printf 'Exiting...\n' scanvirus_trap_flag='true' } # trap keyboard interrupt (control-c) scanvirus_trap_flag='false' trap control_c 2 #commands if [ "$1" = "-mswin" ] || [ "$1" = "-w" ]; then printf "" printf ".....scanvirus mswin.....\n" #blkid -o list scanvirus_flag="false" while read -ra line; do if [ "$scanvirus_flag" = 'false' ]; then scanvirus_flag="true" read -ra line read -ra line #break fi Device_Label=${line[0]} File_System=${line[1]} Drive_Label=${line[2]} Mount_Point=${line[3]} #if file system vfat or ntfs if [ $File_System = 'ntfs' ] || [ $File_System = 'vfat' ]; then #printf "%s %s %s\n" ${line[0]} ${line[1]} ${line[2]} #if device not mounted if [ $Mount_Point = '(not' ]; then printf "__________________________________________________\n" #udisksctl mount -b $devicename -o ro while read -ra command_output; do #printf "%s %s %s %s\n" ${command_output[0]} ${command_output[1]} ${command_output[2]} ${command_output[3]%.} break done < <(udisksctl mount -b "$Device_Label") command_output_mount=${command_output[0]} if [ "$command_output_mount" = 'Mounted' ]; then printf "%s mounted\n" $Drive_Label else printf "Error: unmount %s\n" $Drive_Label fi command_output_scandir=${command_output[3]%.} #code start printf "scanning: %s %s\n" $Drive_Label $command_output_scandir while read -ra command_output_filescan; do printf "%s\n" $command_output_filescan echo `expr index "$command_output_filescan" 'MSWIN64'` break done < <(clamscan -r --move=/home/$USER/VirusVault/ --follow-dir-symlinks=0 --follow-file-symlinks=0 $command_output_scandir) #code end while read -ra command_output; do #printf "%s %s %s\n" ${command_output[0]} ${command_output[1]} ${command_output[2]} break done < <(udisksctl unmount -b "$Device_Label") command_output_unmount=${command_output[0]} if [ "$command_output_unmount" = 'Unmounted' ]; then printf "%s unmounted\n" $Drive_Label else printf "Error: mount %s\n" $Drive_Label fi if [ "$scanvirus_trap_flag" = 'true' ]; then break fi printf "__________________________________________________\n" elif [ "${line[3]}" = '(in' ]; then printf "(in use)\n" else printf "__________________________________________________\n" printf "scanning %s\n" ${line[2]} clamscan --move=/home/$USER/VirusVault/ "$Mount_Point" printf "__________________________________________________\n" fi fi done < <(blkid -o list) elif [ "$1" = "-linux" ] || [ "$1" = "-l" ]; then printf "Scanning linux...\n"; #which scans linux only. Both? #clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --cross-fs=no su -c "freshclam;clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --exclude-dir=/.snapshots --follow-dir-symlinks=0 --follow-file-symlinks=0" #clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --follow-dir-symlinks=0 --follow-file-symlinks=0 #clamscan -r / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --follow-dir-symlinks=0 --follow-file-symlinks=0 --log=scan.log elif [ "$1" = "-help" ] || [ "$1" = "-h" ]; then printf " Scan Virus help commands ------------- -linux or -l: virus scan linux files -mswin or -w: virus scan windows files --setup: setup scanvirus --kdeicons: setup icons \n" elif [ "$1" = "--setup" ]; then printf "\n" printf "ScanVirus Setup...\n" su -c "zypper --non-interactive install clamav;chkconfig freshclam on;freshclam;exit" if [ -d "/home/$USER/VirusVault" ]; then printf "Virus vault directory present\n" else printf "Creating virus vault directory\n" mkdir /home/$USER/VirusVault fi printf "\n" elif [ "$1" = "--kdeicons" ]; then Create_KDE_linux_scan_icon; Create_KDE_windows_scan_icon; printf "KDE Icons Created\n"; else printf " Scan Virus help commands ------------- -linux or -l: virus scan linux files -mswin or -w: virus scan windows files --setup: setup scanvirus --kdeicons: setup icons \n" fi exit 0 # End Of Script
Bookmarks