From d014405e1f637e134f46fcd7b0ac42cbd6a8c1b2 Mon Sep 17 00:00:00 2001 From: Charles Herlin Date: Wed, 6 Feb 2019 17:25:16 +0100 Subject: [PATCH] FIX: add becho to send batch output to syslog too becho stands for batch echo formats the log line for syslog Also logs audit summary into syslog (in batch mode only) --- bin/hardening.sh | 2 +- lib/common.sh | 7 ++++++- lib/main.sh | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/hardening.sh b/bin/hardening.sh index b506b51..7212f5d 100755 --- a/bin/hardening.sh +++ b/bin/hardening.sh @@ -272,7 +272,7 @@ if [ $BATCH_MODE ]; then else BATCH_SUMMARY+=" CONFORMITY_PERCENTAGE:N.A" # No check runned, avoid division by 0 fi - echo $BATCH_SUMMARY + becho $BATCH_SUMMARY else printf "%40s\n" "################### SUMMARY ###################" printf "%30s %s\n" "Total Available Checks :" "$TOTAL_CHECKS" diff --git a/lib/common.sh b/lib/common.sh index e739d54..4c7e212 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -46,11 +46,16 @@ _logger() { COLOR=$1 shift test -z "$SCRIPT_NAME" && SCRIPT_NAME=$(basename $0) - builtin echo "$*" | /usr/bin/logger -t "[CIS_Hardening] $SCRIPT_NAME" -p "user.info" + builtin echo "$*" | /usr/bin/logger -t "CIS_Hardening[$$] $SCRIPT_NAME" -p "user.info" SCRIPT_NAME_FIXEDLEN=$(printf "%-25.25s" "$SCRIPT_NAME") cecho $COLOR "$SCRIPT_NAME_FIXEDLEN $*" } +becho() { + builtin echo "$*" | /usr/bin/logger -t "CIS_Hardening[$$]" -p "user.info" + builtin echo "$*" +} + cecho () { COLOR=$1 shift diff --git a/lib/main.sh b/lib/main.sh index 72cb295..6be3e61 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -113,7 +113,7 @@ esac if [ $CRITICAL_ERRORS_NUMBER -eq 0 ]; then if [ $BATCH_MODE -eq 1 ]; then BATCH_OUTPUT="OK $SCRIPT_NAME $BATCH_OUTPUT" - echo $BATCH_OUTPUT + becho $BATCH_OUTPUT else ok "Check Passed" fi @@ -121,7 +121,7 @@ if [ $CRITICAL_ERRORS_NUMBER -eq 0 ]; then else if [ $BATCH_MODE -eq 1 ]; then BATCH_OUTPUT="KO $SCRIPT_NAME $BATCH_OUTPUT" - echo $BATCH_OUTPUT + becho $BATCH_OUTPUT else crit "Check Failed" fi