1

I want to schedule a daily scan in my Home directory using ClamAv. Can anybody explain me how to perform such task using a bash script? I don't need to scan mails, just Home directory and maybe other directories. Thank you

P.s.: I don't really need it, but is there a way to perform a scan on the whole pc?

1

I would use cron for this instead of strictly using bash. In the directory /etc/cron.daily/ create a small script clamavscan.sh that looks like:

#!/bin/sh
clamscan /home/username/

Then be sure to make the script executable with chmod +x clamavscan.sh. This should run the clamscan of your home directory once daily at 6:25 (as you can see in the file /etc/crontab).


To have ClamAV scan you entire machine, you should just be able to run clamscan /, although this might require root privileges to really scan everything.

  • What will ClamAv do if it finds some threats? – OverMorrow Mar 23 '16 at 1:53
  • I don't know what ClamAv's default behavior is. You could probably set ClamAv to automatically delete/quarantine/whatever the threats so you don't have to deal with them. Otherwise, if you want to make the call manually, you could make a slightly more sophisticated clamavscan.sh script that somehow alerts you to make a decision. At the very least you can redirect the output of the clamscan so you have a logfile to check for threats. – Mike Pierce Mar 23 '16 at 2:30
0

I've been trying to create a similar cron job myself today. I went a slightly different route. I opened up /etc/crontab and added the following job:

0 18 * * SUN root rm -rf /var/log/clamav/freshclam.log
1 18 * * SUN root freshclam
22 18 * * SUN root clamscan -r -i / | grep FOUND >> /home/osamu/virus-scan-reports/virus-scan-report-`date +"\%d-\%m-\%Y"`.txt

If someone else has a better way to schedule regular virus scans including updating the known virus database please reply this thread.

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.