http://linux.die.net/man/1/clamscan
I won’t have access to my computer for a while, some unrelated issues. Using another person’s computer at the moment.
hcvv: Again it is a bit difficult to understand this. While almost nobody here knows the program clamscan or has it installed, we have no example of it’s output. Thus a piece of real data with an explanation of what lines (parts of lines) should trigger what action might be helpful. E.g., when you want to read a line into variables (or an array), the first thing to determine is what the separator between the parts should be (the IFS variable). By choosing it carefully, things can be made easier.
IFS=’ ’ #The default right?
Also you only present the script, but do not present us with any problem it gives you. Does it run? Does it give errors? Does it produce output, but different from what you hoped for?
The last code produced no output at all and clamscan became background task. I want to display the current top level directory being scan. I’v having trouble with extracting strings from the output.
Here’s an example of typical clamscan output:
[FONT=Verdana][size=2]#Virus found
/var/lib/rpm/Packages: UNIX.Exploit.CVE_2010_3301 FOUND
[FONT=Verdana][size=2][FONT=Verdana][size=2][directory tree]: [virus found]
#Virus not found
/var/lib/rpm/Packages: OK
[/size][/size][/FONT][/FONT][/size][/FONT]
[FONT=Verdana][size=2][FONT=Verdana][size=2][FONT=Verdana][size=2][FONT=Verdana][size=2][FONT=Verdana][size=2][FONT=Verdana][size=2][FONT=Verdana][size=2][directory tree]: [virus not found][/size][/size][/size][/size][/size][/size][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/size][/FONT]
Here’s one method.
DriveLabel="MSWINXX"
IFS=' '
while read -ra command_output_filescan; do #read output of clamscan into string array command_output_filescan
#Process clamscan output
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" $DriveLabel` #find the beginning of drive_label and print
break #stop here just first line only.
#end
#Do a recursive scan of an ntfs windows directory and capture the output.
done < <(clamscan -r "/mounted/MSWINXX/")
Another method, send the scan to ‘clamav.log’
#Do a recursive scan of an ntfs windows directory and capture the output.
clamscan -r "/media/MSWINXX/" -l clamav.log
DriveLabel="MSWINXX"
IFS=' '
while read -ra command_output_filescan; do
#Process clamscan output
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" $DriveLabel` #find the beginning of drive_label and print
break #stop here just first line only.
#end
done < < "clamav.log"