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
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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.
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
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'