ClamAV 复制已检查的非感染文件

ClamAV copy checked non infected files

我目前正在编写一个脚本,用于检查 U 盘中是否存在在 Raspberry Pi 上运行的恶意文件。

对于 AV 检查,我使用 clamscan 这样的:

clamscan --infected --allmatch --detect-pua --block-macros --recursive --block-encrypted $start_directory

其中 $start_directory 是 USB 驱动器的安装点。

clamscan 有一个针对受感染文件的 --move 选项。但是如何自动将 clamscan 测试为 OK 的文件复制到所需目录?

我认为没有否定选项 clamscan 所以你可以 做一些像

declare -a infectedlist=( $(clamscan --infected --allmatch --detect-pua --block-macros --recursive --block-encrypted "$start_directory") )
shopt -s globstar
for i in "$start_directory"/**
do
[[ ! -f "$i" ]] && continue # If not a file then next item !!
 found=0
 for j in "${infectedlist[@]}"
 do
  [[ "$i" = "$j" ]] && found=1
 done
 [ "$found" -eq 0 ] && mv "$i" /desired/directory
done
shopt -u globstar #unset globstar

作为旁注双引号变量,即 "$start_directory" to avoid word splitting.