I'm not sure why you have the loop for
for FILE in "$DIR"/* when you follow it up with
clamscan -r "$FILE"
The
-r flag asks
clamscan to recursively search. This will call
clamscan once for each item in the directory. Can you not just
clamscan -r "$DIR" instead? I find that running
clamscan has a several second overhead as it loads up the definitions. You could be scanning for hours just on calling the process repeatedly. An alternate might be to list the files into another file and use that as input with the
-f flag, e.g.
clamscan -if /tmp/file_list.txt
I've added the
-i flag to only list infected files, which might make reading the output easier.
You have the basis of some good code here though, keep going
Do you have a virus signature to test this with?
Robin