Skip to content

Instantly share code, notes, and snippets.

@aiya000
Forked from nemasu/virus_scan.sh
Last active February 24, 2025 16:39
Show Gist options
  • Save aiya000/e7ce3e9909f122b60c464af0200bf905 to your computer and use it in GitHub Desktop.
Save aiya000/e7ce3e9909f122b60c464af0200bf905 to your computer and use it in GitHub Desktop.
Progress for clamdscan.
#!/bin/bash
# This respects the following original script:
# - Original: https://gist.github.com/nemasu/9d89d2998822980a07284bf442342482
#
# I'm also developing the newer version at here:
# - Support: https://github.com/aiya000/bash-toys
if [[ $# -eq 0 ]] ; then
target_paths=(/)
else
target_paths=("$*")
fi
if command -v fdfind > /dev/null 2>&1 ; then
find_target_paths="fdfind . ${target_paths[*]} --min-depth 1 --exclude \"/{proc,sys,run,dev,snap,mnt}\" --type d"
elif command -v fd > /dev/null 2>&1 ; then
find_target_paths="fd . ${target_paths[*]} --min-depth 1 --exclude \"/{proc,sys,run,dev,snap,mnt}\" --type d"
else
find_target_paths="find ${target_paths[*]} -mindepth 1 -not -path \"/proc\" -not -path \"/sys\" -not -path \"/run\" -not -path \"/dev\" -not -path \"/snap\" -not -path \"/mnt\" -type d"
fi
logfile="/tmp/clamdscan_$(date '+%Y-%m-%d-%H-%M').log"
count=0
function show_progress () {
echo -ne "\r"
echo -n "$(echo "scale=5; ($count / $total) * 100" | bc)"
}
IFS=$'\n'
touch "$logfile"
total=$(eval "$find_target_paths" | wc -l)
for dir in $(eval "$find_target_paths" 2>/dev/null) ; do
count=$((count + 1))
show_progress
echo "$dir" >> "$logfile"
for file in $(fdfind --full-path "$dir" --min-depth 1 --max-depth 1 --type f 2>/dev/null) ; do
clamdscan --fdpass --quiet "$file"
done
done
echo
@aiya000
Copy link
Author

aiya000 commented Feb 24, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment