Clam AV weekly cron job to scan last 7 days of files in home3/* home5/*

Operating System & Version
CentOS v7.9.2009 STANDARD standard
cPanel & WHM Version
106.0.7

Nermin

Member
Mar 7, 2017
16
4
53
Tuzla
cPanel Access Level
Root Administrator
Hello,

I am trying to make weekly cron job to scan new files in "home3/*/mail" and "home5/*/mail" folders and to remove them if infected, but only for last 7 days of new files.

Currently I have this working pretty good, but it takes too long for it to finish because it scans all files in mail folders:
/usr/local/cpanel/3rdparty/bin/clamscan -ir --remove /home4/*/mail/ /home5/*/mail/ | mail -s "Finished weekly scan and deletion of emails in folder mail" [email protected]

I would like to scan only new files and make it run once a week, and maybe daily in future.
Currenty it scans directories: 40966 and files: 3076744. I would like to speed things up and make it use less resources.

Does anybody know how can I achieve this?

I have found this, but not tested:
find /home4/*/mail/ /home5/*/mail/ -ctime -1 -type f -print0 | xargs -0 /usr/local/cpanel/3rdparty/bin/clamscan --remove mail -s "Finished weekly scan and deletion of emails in folder mail" [email protected]
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
13,259
2,086
363
cPanel Access Level
Root Administrator
Hey there! I'm not sure that "ctime -1" is going to give you the results you want. You might want to try "mtime 7" instead of that ctime option, as that would grab any files between now and 7 days old.

You can also just run the first half of the command, slightly modified, to see if the output is what you expect, before passing it to the clamscan commands:

Code:
find /home4/*/mail/ /home5/*/mail/ -mtime 6 -type f > output.file
That would create a file named "output.file" so you can examine the contents.
 

Nermin

Member
Mar 7, 2017
16
4
53
Tuzla
cPanel Access Level
Root Administrator
I think I've did it with this two cron jobs:
0 5 * * 1-6 find /home4/*/mail /home5/*/mail -ctime -8 -type f -print > /home3/lista_8_dana.txt | mail -s "List is created" [email protected]
30 5 * * 7 /usr/local/cpanel/3rdparty/bin/clamscan --infected --remove --scan-mail --phishing-sigs --phishing-scan-urls --algorithmic-detection --scan-pe --scan-elf --scan-ole2 --scan-pdf --scan-html --file-list=/home3/lista_8_dana.txt | mail -s "Scanning completed" [email protected]
 
  • Like
Reactions: cPRex