From 97a98c8df356ae69ad24b2bd20b7b079db66fd36 Mon Sep 17 00:00:00 2001 From: William Hirigoyen Date: Fri, 17 Feb 2023 10:48:30 +0100 Subject: [PATCH] Log runtime config to /var/log/evocheck.log --- linux/CHANGELOG | 2 +- linux/evocheck.sh | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/linux/CHANGELOG b/linux/CHANGELOG index 4ba4aa3..34da9ad 100644 --- a/linux/CHANGELOG +++ b/linux/CHANGELOG @@ -5,7 +5,7 @@ and this project **does not adhere to [Semantic Versioning](http://semver.org/sp ### Added -* Log output to /var/log/evocheck.log. +* Log output and runtime config to /var/log/evocheck.log. ### Changed diff --git a/linux/evocheck.sh b/linux/evocheck.sh index 422bc86..bb6f58f 100755 --- a/linux/evocheck.sh +++ b/linux/evocheck.sh @@ -101,9 +101,14 @@ is_installed(){ # logging log() { - msg="${1}" date=$(/bin/date +"${DATE_FORMAT}") - printf "[%s] %s: %s\\n" "$date" "${PROGNAME}" "${msg}" >> "${LOGFILE}" + if [ "${1}" != '' ]; then + printf "[%s] %s: %s\\n" "$date" "${PROGNAME}" "${1}" >> "${LOGFILE}" + else + while read line; do + printf "[%s] %s: %s\\n" "$date" "${PROGNAME}" "${line}" >> "${LOGFILE}" + done < /dev/stdin + fi } failed() { @@ -1514,6 +1519,9 @@ readonly ARGS LOGFILE="/var/log/evocheck.log" readonly LOGFILE +CONFIGFILE="/etc/evocheck.cf" +readonly CONFIGFILE + DATE_FORMAT="%Y-%m-%d %H:%M:%S" # shellcheck disable=SC2034 readonly DATEFORMAT @@ -1528,7 +1536,7 @@ trap cleanup_temp_files 0 # Source configuration file # shellcheck disable=SC1091 -test -f /etc/evocheck.cf && . /etc/evocheck.cf +test -f "${CONFIGFILE}" && . "${CONFIGFILE}" # Parse options # based on https://gist.github.com/deshion/10d3cb5f88a21671e17a @@ -1578,6 +1586,12 @@ done log "Running $PROGNAME $VERSION..." +# Log config file content +if [ -f "${CONFIGFILE}" ]; then + log "Runtime configuration (${CONFIGFILE}):" + sed -e '/^[[:blank:]]*#/d; s/#.*//; /^[[:blank:]]*$/d' "${CONFIGFILE}" | log +fi + # shellcheck disable=SC2086 main ${ARGS}