From ff92e3889e79f372ed531dacaa21f62d97e49e36 Mon Sep 17 00:00:00 2001 From: William Hirigoyen Date: Fri, 17 Feb 2023 12:53:31 +0100 Subject: [PATCH] Log program exit --- linux/evocheck.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/linux/evocheck.sh b/linux/evocheck.sh index bb6f58f..941d903 100755 --- a/linux/evocheck.sh +++ b/linux/evocheck.sh @@ -1503,9 +1503,12 @@ main() { exit ${RC} } -cleanup_temp_files() { +cleanup() { + # Cleanup tmp files # shellcheck disable=SC2086,SC2317 rm -f ${files_to_cleanup[@]} + + log "$PROGNAME exit." } PROGNAME=$(basename "$0") @@ -1530,10 +1533,6 @@ readonly DATEFORMAT export LANG=C export LANGUAGE=C -declare -a files_to_cleanup -# shellcheck disable=SC2064 -trap cleanup_temp_files 0 - # Source configuration file # shellcheck disable=SC1091 test -f "${CONFIGFILE}" && . "${CONFIGFILE}" @@ -1584,6 +1583,14 @@ while :; do shift done +# Keep this after "show_version(); exit 0" which is called by check_versions +# to avoid logging exit twice. +declare -a files_to_cleanup +files_to_cleanup="" +# shellcheck disable=SC2064 +trap cleanup EXIT INT TERM + +log '-----------------------------------------------' log "Running $PROGNAME $VERSION..." # Log config file content