I am working on creating some custom logging rules for clamav
. The default output from a scan is extremely long as it reports everyfile. The default logging doesnt even include timestamp so I added that to each entry of the log file. What I really want to capture is
FOUND
for when an infection is found. and I want to capture Mon Dec 9 19:29:53 UTC 2019Scanned files: 45
which tells me scan was completed and how many files were scanned
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/dshield.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-games.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-worm.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-tftp.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-deleted.rules: Html.Trojan.Blackhole-65 FOUND
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-icmp_info.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-web_client.rules: Html.Exploit.CVE_2018_8373-6654754-1 FOUND
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-policy.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-shellcode.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-info.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-smtp.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-pop3.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-current_events.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-attack_response.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-mobile_malware.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/tor.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-p2p.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-web_server.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-telnet.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-dns.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-scan.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-dos.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-malware.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-ftp.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/botcc.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-rpc.rules: OK
Mon Dec 9 19:29:53 UTC 2019/tmp/clamav_test/emerging-snmp.rules: OK
Mon Dec 9 19:29:53 UTC 2019
Mon Dec 9 19:29:53 UTC 2019----------- SCAN SUMMARY -----------
Mon Dec 9 19:29:53 UTC 2019Known viruses: 6594198
Mon Dec 9 19:29:53 UTC 2019Engine version: 0.101.4
Mon Dec 9 19:29:53 UTC 2019Scanned directories: 1
Mon Dec 9 19:29:53 UTC 2019Scanned files: 45
Mon Dec 9 19:29:53 UTC 2019Infected files: 2
Mon Dec 9 19:29:53 UTC 2019Data scanned: 38.73 MB
Mon Dec 9 19:29:53 UTC 2019Data read: 15.07 MB (ratio 2.57:1)
Mon Dec 9 19:29:53 UTC 2019Time: 50.946 sec (0 m 50 s)
This will capture any infections and write them here
clamscan -r --exclude=/sys | grep "FOUND" | sed "s/^/$(date)/ " >> /var/log/clamav/alerts/infections.log
This will capture the Scanned Files at completion of the output.
clamscan -r --exclude=/sys | grep "Scanned" | sed "s/^/$(date)/ " >> /var/log/clamav/alerts/scans.log
How the hell can I do that with one command?