Skip to content

Instantly share code, notes, and snippets.

@richlamdev
Forked from svantoviit/virus-scan.sh
Created October 8, 2023 03:47
Show Gist options
  • Save richlamdev/4c7b17dd512b595cc978e7fa43d29a3f to your computer and use it in GitHub Desktop.
Save richlamdev/4c7b17dd512b595cc978e7fa43d29a3f to your computer and use it in GitHub Desktop.
Watch download directory and scan downloaded files with ClamAV
#!/bin/bash
#
# Watch download directory and scan downloaded files with ClamAV
#
# Check if works by downloading:
# https://secure.eicar.org/eicar_com.zip
#
# Original script by Fitzcarraldo
# https://fitzcarraldoblog.wordpress.com/2016/02/20/\
# automatically-detecting-files-placed-in-my-downloads-directory-in-\
# gentoo-linux-and-scanning-them-for-viruses/
DIR="${HOME}/Downloads"
LOG="${HOME}/.my-virus-scan.log"
while read -r file; do
# Have to check file length is nonzero otherwise commands may be repeated
if [[ -s "${file}" ]]; then
date > "${LOG}"
clamscan --quiet -l "${LOG}" "${file}"
# Display notification only if virus found or error occurred
if [[ $? -ne 0 ]]; then
zenity --warning --title "Virus scan of ${file##*/}" \
--text "$(cat "${LOG}")" 2>/dev/null
fi
fi
done < <(inotifywait -q -m -e close_write,moved_to --format '%w%f' "${DIR}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment