1

When using Clam AntiVirus from within GNU Bash, how should one invoke clamscan such that it will reliably suppress all output except the final summary?

These attempts don't work:

  • clamscan --quiet. Suppresses the final summary.
  • clamscan -o -r ~/ 2>/dev/null. Prints lines that aren't "OK" (but which don't necessarily indicate an infection: e.g. files that are simply empty files, or symbolic links) to stdout. Those lines therefore bypass the redirect and are still printed on the terminal in addition to the final summary.
0

There are no such switches provided by clamscan itself to suppress output, but you can pipe it's output or generated log file to an awk script to filter.

Assuming -o is set and -v is not set.

File: filter.awk: (set chmod +x filter.awk)

#!/bin/awk -f
BEGIN {
        split("Symbolic link,Excluded,Empty file", col2, ",")
        FS=": "
}
{
        skip_line = 0
        for (i in col2) {
                if ($2 == col2[i]) {
                        skip_line++
                        break
                }
        }
        # uncomment next 4 lines below to remove FOUND info
        #if (skip_line == 0) {
        #        if ($2 ~ /FOUND/) {
        #                skip_line++
        #        }
        }

        if (skip_line == 0) {
                print $line
        }
}

example usage:

clamscan -o -r /home | /path/filter.awk

or

cat /var/log/clamscan.log | /path/filter.awk
  • Thanks for this, but it seems that rather than solely affecting clamscan's output, your suggested solution would also affect clamscan's behaviour. For example, if the user wanted to suppress all clamscan output except the summary, while still including directory and file symlinks, then your solution would not work, because it would achieve the former only at the expense of the latter. – sampablokuper Nov 2 '16 at 18:18
  • I've updated my answer.. good luck – Michael D. Nov 2 '16 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.