clamscan and cpulimit together runs multiple clamscan processes

jaimbh

New Member
Joined
Jan 28, 2023
Messages
1
Reaction score
0
Credits
22
I have installed clamav and cpulimit.
I want to clamscan all directories in /home which are not owned by root 1 by 1 with a cpu limit of 70%.
I use the below command to do that in centos and almalinux:
find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root -exec cpulimit -l 70 -- /usr/bin/clamscan -i -r {} \; > /root/scan_results.txt

The above command works fine in centos. But in ubuntu 18 and 20, it creates multiple clamscan processes for each directory which are in /home and all the processes consume 70% cpu usage thereby overloading my server. I checked that using 'top' command.
'ps aux | grep clamscan' command also shows multiple clamscan processes running simultaneously.

find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root -exec /usr/bin/clamscan -i -r {} \; > /root/scan_results.txt
When I remove cpulimit from the command like shown above, it scans 1 by 1 but clamscan process consumes 100% cpu usage which I dont want.

I tried some other commands which didnt work as well:
1) find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root | xargs -I {} cpulimit -l 70 -- /usr/bin/clamscan -i -r {} > /root/scan_results.txt
2) find /home/ -mindepth 1 -maxdepth 1 -type d ! -user root | xargs -P 1 -I {} cpulimit -l 70 -- /usr/bin/clamscan -i -r {} > /root/scan_results.txt

I want a command which scans all the /home directories which are not owned by root one at a time with cpulimit of 50% and not simultaneously.
 


Latest posts

Top