I am trying to use bash
to automate the scan of a specific directory using clamav
. Having this in place is a network requirement. The below is an attempt to:
-
count the extensions (.txt, .jpeg) in a directory and write them to a
virus-scan.log
(section in bold) -
scan each folder in the
dir
and log the results of the scan bydate
. (section in italics)
Each folder in the directory is scanned and the results of each day the scan is run is logged to /HOME/virus-scan.log
by date.
Thank you :).
#!/bin/bash
DIR=/home/cmccabe/Desktop/NGS/API
line_no=$(ls | awk -F . '{print $NF}' | sort | uniq -c | awk '{print $2,$1}') # count folder type and store as variable
echo >> $HOME/virus-scan.log"The folders detected are:
$line_no"
# Get rid of old log file
rm $HOME/virus-scan.log 2> /dev/null
while read FILE in $DIR;
do
# check file length is nonzero otherwise commands may be repeated
if [ -s $FILE ]; then
date > $HOME/virus-scan.log
clamscan -r $FILE >> $HOME/virus-scan.log
else "echo nothing detected by scan"
fi
done