How to play a song when a virus is detected with clamav from command line ? A song and not a bell .

For information I do this to scan with a bell : clamscan -r --bell -i /media


  • 1
    Write a script clamscan -i ... ; [ $? -eq 1 ] && aplay /path/to/song Cant be more specific with what little you posted . – Panther Oct 25 '17 at 0:54
  • Post your script / command as an answer you did the work, I just nudged you . – Panther Oct 26 '17 at 23:13

It appears clamscan(1) sends its output to stdout so pipe it to tee which will send the output to stdout and to a command that filters for "Virus detected" and whan that is found, it invokes your program to play music. From the clam AntiVirus user's manual, it appears the output will be what this line produces:

printf("Virus detected: %s\n", virname);

Something like this should work:

clamscan |tee (grep "Virus detected" | yourprogram_or_script musicfile )

See https://raw.githubusercontent.com/vrtadmin/clamav-faq/master/manual/clamdoc.pdf and clamscan(1) and tee(1) for more info.

  • I have tried that but sorry this do not work and that is more easy : ; [ $?-eq 1] && For example : /usr/bin/clamscan -r -l /var/log/clamscan_sched_$d.log /home/pi/Desktop; [ $? -eq 1 ] && espeak -v en+f2 -s 150 'Warning, a virus has been detected' – FI0RlAN-X Oct 26 '17 at 22:55

From the comments, FI0RlAN-X answered with :

/usr/bin/clamscan -r -l /var/log/clamscan_sched_$d.log /home/pi/Desktop; [ $? -eq 1 ] && espeak -v en+f2 -s 150 'Warning, a virus has been detected'

To break that up a bit, the clamscan options, from man clamscan

-r, --recursive

          Scan  directories  recursively.  All  the  subdirectories in the
          given directory will be scanned.  

-l FILE, --log=FILE

          Save scan report to FILE.


  0 : No virus found.

  1 : Virus(es) found.

  2 : Some error(s) occured.

So the second comand, $? is the return code from clamscan , so test if the retrun code is 1 (virus found) [ $? -eq 1 ] and play a sound using a sound with espeak espeak -v en+f2 -s 150 'Warning, a virus has been detected'

[ $? -eq 1 ] && espeak -v en+f2 -s 150 'Warning, a virus has been detected'

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.