scan virus display current directory being scanned, opensuse - kde

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.


#!/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 "__________________________________________________
"
#              printf "scanning %s
" $line
#              clamscan $line
#              printf "__________________________________________________
"
#              printf "
"
#            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...
'
  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.....
"

        #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
" ${line[0]} ${line[1]} ${line[2]}

             #if device not mounted
             if  $Mount_Point = '(not' ]; then
                 printf "__________________________________________________
"

                 #udisksctl mount -b $devicename -o ro
                 
                 while read -ra command_output; do
                   #printf "%s %s %s %s
" ${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
" $Drive_Label
                 else
                    printf "Error: unmount %s
" $Drive_Label
                 fi
                 command_output_scandir=${command_output[3]%.}

                 #code start
                 printf "scanning: %s %s
" $Drive_Label $command_output_scandir
                 while read -ra command_output_filescan; do
                   printf "%s
" $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
" ${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
" $Drive_Label
                 else
                    printf "Error: mount %s
" $Drive_Label
                 fi

                 if  "$scanvirus_trap_flag" = 'true' ]; then
                    break
                 fi
        
                 printf "__________________________________________________
"
             elif  "${line[3]}" = '(in' ]; then
               printf "(in use)
" 
             else
                 printf "__________________________________________________
"
                 printf "scanning %s
" ${line[2]}
                 clamscan --move=/home/$USER/VirusVault/ "$Mount_Point"  
                 printf "__________________________________________________
"
             fi
         fi             
           
         done < <(blkid -o list)

    elif  "$1" = "-linux" ] ||  "$1" = "-l" ]; then
        printf "Scanning linux...
"; 
          #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

"           

    elif  "$1" = "--setup" ]; then
        printf "
"
        printf "ScanVirus Setup...
"
        su -c "zypper --non-interactive install clamav;chkconfig freshclam on;freshclam;exit"
 
        if  -d "/home/$USER/VirusVault" ]; then
          printf "Virus vault directory present
"
        else
          printf "Creating virus vault directory
"
          mkdir /home/$USER/VirusVault
        fi
        printf "
"

    elif  "$1" = "--kdeicons" ]; then
            Create_KDE_linux_scan_icon;
            Create_KDE_windows_scan_icon;  
            printf "KDE Icons Created
";
      
    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

"           
    fi
exit 0
# End Of Script


While it is possible that there are people that will study this complete script from top to bottom to get enough understanding of it to see what you mean, I think it is not the best way to isolate the problem in a way that it, and only it, is presented to yourself as well as to potential helpers.

It is alway best to break down such a script/program and throw away anything that is superfluous to the kernel of the problem. It will help you in having a small test program to experiment with and it will help us in understanding the problem quickly.

I have no idea if you tried this already, but IMHO it is worthwhile.

On 2015-09-08 10:16, hcvv wrote:
>
> While it is possible that there are people that will study this complete
> script from top to bottom to get enough understanding of it to see what
> you mean, I think it is not the best way to isolate the problem in a way
> that it, and only it, is presented to yourself as well as to potential
> helpers.
>
> It is alway best to break down such a script/program and throw away
> anything that is superfluous to the kernel of the problem. It will help
> you in having a small test program to experiment with and it will help
> us in understanding the problem quickly.

Yes, absolutely. The script is so long that I shied away from reading
it. To complex. I don’t understand what the problem may be with the
script from the description, but it is too big for me to study and find
out (unless I have some big enticing :slight_smile: )


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

This code can be taken out and function alone. I’m trying to capture the output of clamscan and filter the output.


#command_output_filescan[0]= "[file directory tree]:"
#[linux filetree]/MSWIN64/[windows top level directory]
#command_output_filescan[1]= "ok" or "found virus"

  printf "scanning: %s %s
" $drive_label $command_output_scandir   #show drive label and directory scanned
  while read -ra command_output_filescan; do                        #read output of clamscan into string array command_output_filescan

    printf "%s%s
" $command_output_filescan[0] $command_output_filescan[1]   #print drive directory tree and virus scan result
    echo `expr index "$command_output_filescan" "$drive_label"`               #find the beginning of drive_label
    #/MSWIN/toplevel/
    break  #stop here

    done < <(clamscan -r --move=/home/$USER/VirusVault/ --follow-dir-symlinks=0 --follow-file-symlinks=0 $command_output_scandir)     

Simplified.


  while read -ra command_output_filescan; do                        #read output of clamscan into string array command_output_filescan

    printf "%s%s
" $command_output_filescan[0] $command_output_filescan[1]   #print drive directory tree and virus scan result
    echo `expr index "$command_output_filescan" "/mswinxx/"`                  #find the beginning of drive_label and print
    #/MSWIN/toplevel/
    break  #stop here

    done < <(clamscan  -r "/media/mswinxx/")     

I’ll start again, get it down to basics. End Topic.