如何使用 clamav 仅扫描过去 24 小时的文件

Ehs*_*san 3 anti-virus command-line-interface clamav

我创建了一个 bash 脚本来通过 clamav 扫描整个服务器的病毒。该脚本每晚都通过 cron 运行。因此,我只想扫描过去 24 小时内添加的文件。现在我在我的脚本中使用这个命令:

find /home -type f -mmin -1440  -print0 | xargs -0 -r clamscan --infected
Run Code Online (Sandbox Code Playgroud)

但是太慢了,是find命令慢的原因吗?如果是这样,使用 clamscan 仅扫描过去 24 小时的文件的更好方法是什么?clamav 是否可以选择这样做?

任何帮助将非常感激。

小智 8

我在寻找 clamscan 脚本时偶然发现了这个页面。我遵循了上述建议并使其与:

#!/usr/bin/bash
# Create Hourly Cron Job With Clamscan

# Directories to scan
scan_dir="/home"

# Temporary file
list_file=$(mktemp -t clamscan.XXXXXX) || exit 1

# Location of log file
log_file="/var/log/clamav/hourly_clamscan.log"

# Make list of new files
if [ -f  "$log_file" ]
then
        # use newer files then logfile
        find "$scan_dir" -type f -cnewer "$log_file" -fprint "$list_file"
else
        # scan last 60 minutes
        find "$scan_dir" -type f -cmin -60 -fprint "$list_file"
fi

if [ -s "$list_file" ]
then
        # Scan files and remove (--remove) infected
        clamscan -i -f "$list_file" --remove=yes > "$log_file"

        # If there were infected files detected, send email alert
        if [ `cat $log_file | grep Infected | grep -v 0 | wc -l` != 0 ]
        then
                HOSTNAME=`hostname`
                echo "$(egrep "FOUND" $log_file)" | mail -s "VIRUS PROBLEM on $HOSTNAME" -r     clam@nas.local you@yourhost.com
        fi
else
        # remove the empty file, contains no info
        rm -f "$list_file"
fi
exit
Run Code Online (Sandbox Code Playgroud)

在我的情况下,这是一个每小时脚本,但应该每天工作(修改第二个查找)。