Learning Academy

The Cure of Ignorance is to Question. MUHAMMAD (PBUH)

CentOS

How to install CLAMAV with update DB script and Scanning on CentOS?


Script to update clamav and Start scanning via Cron

So, lets create a script to update clamav db and then start scanning via Cron Daemon.

vi /etc/cron.daily/clamav_scan

 

#!/bin/bash

# ———————————————————————-

# Virus scan with ClamAV

# ———————————————————————- 

# Disabling PATH improves the security of the script

unset PATH

# Declare the variables

ECHO=/bin/echo;

DATE=/bin/date;

FRESHCLAM=/usr/bin/freshclam;

CLAMSCAN=/usr/bin/clamscan;

LOG_FILE=/var/log/clamav/clamscan.log;

SCAN_FOLDER=/home;


# Start the log entry

$ECHO Complete system virus scan starting >> $LOG_FILE;

$DATE >> $LOG_FILE;

$ECHO \* >> $LOG_FILE;


# Update Virus definitions

$FRESHCLAM >> $LOG_FILE;


# Run the scan

$CLAMSCAN -ri $SCAN_FOLDER >> $LOG_FILE;


# Finish the log entry

$ECHO \* >> $LOG_FILE;

$ECHO Complete system virus scan finished >> $LOG_FILE;

$DATE >> $LOG_FILE;

$ECHO \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* >> $LOG_FILE;

Note:

  • As per this script you have to manually check log file for any possible infective files.
  • You can change directory for scanning by modify SCAN_FOLDER=/home;

Muhammad Shaukat

Content Developer at LearnAcad.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest