Schedule Daily Anti-Virus Scan With ClamAV


INTRODUCTION

This will explain how to create a daily cron job to scan the Control Web Panel (CWP) user directories and create a report on AlmaLinux.


READ ME FIRST

This article is provided as a courtesy.
Installing, configuring, and troubleshooting third-party applications is outside the scope of basic support provided by Starburst Services.

We are not liable for any damages and/or data loss.


REQUIRMENTS

  • SSH credentials or File Manager access Logged In as Root
  • Text editor of your choice. (The example uses nano)
  • If you need help creating the time for a cron job see: Cron Job Scheduler Helper

PROCEDURE

STEP 1

After logging into the CLI.

Make a directory when the reports will be saved.

In this example, we use /virus-scan-reports:

mkdir /root/virus-scan-reports

STEP 2

Goto the cron jobs directory:

cd /var/spool/cron

STEP 3

Open the ‘root’ cron job:

nano root

STEP 4

In this example (using 2024-08-21), we create a Daily job at 20:22 (8:22 PM), with a Log File going to /root/virus-scan-reports, and a name of virus-scan-report-2024-08-21.txt

At the bottom of the job add (this is all 1 line, NOT 2):

22 20 * * * clamscan --infected --log=/root/virus-scan-reports/virus-scan-report-`date +\%Y-\%m-\%d`.txt --recursive /home

Save & Exit

Save: Ctrl-O
Exit: Ctrl-X


STEP 5 (Optional, but Recommended)

To test and make sure everything works correctly, it is suggested, you run the command 1 time from /:

clamscan --infected --log=/root/virus-scan-reports/virus-scan-report-`date +\%Y-\%m-\%d`.txt --recursive /home

Then goto:

cd /root/virus-scan-reports

List the files:

ls

Open report you just created with nano, in this example it was:

nano virus-scan-report-2024-08-21.txt

If all is good, you should see something like:

------------------------------------

----------- SCAN SUMMARY -----------
Known viruses: 8758362
Engine version: 0.103.11
Scanned directories: xxx
Scanned files: xxxx
Infected files: y
Data scanned: x.x MB
Data read: xxxx.x MB (ratio x:z)
Time: xxxx.xxx sec (xx m x s)
Start Date: 2024:08:21 15:46:23
End Date: 2024:08:21 15:57:26


Now, you’ve configured a Daily cron job to run ClamAV to scan all the directories within /home on AlmaLinux.


Thanks for learning with Starburst Services.

Learn more about our services


Did you found this Knowledge Base Article useful?

Please considering thanking our SysOp Team.


KB Article Written: 2024-08-21

people found this article helpful. What about you?