From 3fbee61d3094ce7357b489e8e6525c8501db8810 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Tue, 29 Mar 2016 18:46:05 +0000 Subject: [PATCH] While /tmp is likely cleaned automatically, any crash in the shell script would have left over. Using trap should prevent that. --- roles/clamav/templates/clamscan.sh.j2 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roles/clamav/templates/clamscan.sh.j2 b/roles/clamav/templates/clamscan.sh.j2 index 0c521806f5..afe94cb279 100644 --- a/roles/clamav/templates/clamscan.sh.j2 +++ b/roles/clamav/templates/clamscan.sh.j2 @@ -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