Skip to content

Instantly share code, notes, and snippets.

@svantoviit
Last active December 19, 2023 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save svantoviit/767d1ba42eefaef17fdf to your computer and use it in GitHub Desktop.
Save svantoviit/767d1ba42eefaef17fdf 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