While /tmp is likely cleaned automatically, any crash in the shell script

would have left over. Using trap should prevent that.
This commit is contained in:
Michael Scherer 2016-03-29 18:46:05 +00:00 committed by Kevin Fenzi
parent b811b3daf4
commit 3fbee61d30

View file

@ -9,8 +9,15 @@ DAYS=7
TMPCLAMDIR=$(mktemp -d clamav_ansible.XXXXXX)
FILELIST="$TMPCLAMDIR/clamscan_filelist.$$"
clean_tmp_files() {
rm -f $FILELIST
rmdir $TMPCLAMDIR
}
trap clean_tmp_files EXIT
rm -f $LOGFILE
# Build file list to scan
{% for path in clamscan_paths %}
find {{ path }} -ctime -${DAYS} -type f >> $FILELIST
@ -34,4 +41,3 @@ then
mail -s "Virus scanning error on $(hostname)" $MAILTO -- < $LOGFILE
fi
rm -f $FILELIST