diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index 8b58ad73..08b79eb8 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -277,6 +277,11 @@ some initial files have to be generated from templates before ngcpcfg final setu Ignore schema validation results for YAML files (syntax check is still performed). + **--summary-only** []:: + +Hide all the output except the last summary line. +Useful for integration of ngcpcfg in other scripts/tools. + **--validate** []:: Force schema validation for YAML files even if validation is disabled in config. diff --git a/functions/logs b/functions/logs index 7b71a5e9..e593019d 100644 --- a/functions/logs +++ b/functions/logs @@ -21,35 +21,40 @@ console_output() { # }}} ## logging functions {{{ -log_info() { +log_only() { logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "$*" +} + +log_info() { + log_only "$*" console_output "$*\n" } # info without ending newline log_info_n() { - logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "$*" + log_only "$*" console_output "$*" } log_warn() { - logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Warning: $*" + log_only "Warning: $*" console_output "Warning: $*\n" } +# warning without ending newline log_warn_n() { - logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Warning: $*" + log_only "Warning: $*" console_output "Warning: $*" } log_error() { - logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Error: $*" + log_only "Error: $*" console_output "Error: $*\n" >&2 } log_debug() { if [ -n "${DEBUG:-}" ] ; then - logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Debug: $*" + log_only "Debug: $*" console_output "DEBUG: $*\n" >&2 fi } diff --git a/sbin/ngcpcfg b/sbin/ngcpcfg index 15e7b408..f98fc79b 100755 --- a/sbin/ngcpcfg +++ b/sbin/ngcpcfg @@ -33,10 +33,30 @@ ngcpcfg_restore_perms() { } action() { + local rc=0 ACTION="$1" shift - log_debug "${SCRIPTS}/${ACTION} $*" - "${SCRIPTS}/${ACTION}" "$@" + + [ -z "${SUMMARY_ONLY:-}" ] && SUMMARY_ONLY=0 + + if [ "${SUMMARY_ONLY}" == "1" ]; then + log_debug "${SCRIPTS}/${ACTION} $* >/dev/null 2>&1" + "${SCRIPTS}/${ACTION}" "$@" >/dev/null 2>&1 || rc=$? + else + log_debug "${SCRIPTS}/${ACTION} $*" + "${SCRIPTS}/${ACTION}" "$@" || rc=$? + fi + + if [ "${rc}" == "0" ]; then + local msg="Successfully executed '${ACTION}' on '${HNAME}'" + [ "${SUMMARY_ONLY}" == "1" ] || log_only "${msg}" + [ "${SUMMARY_ONLY}" == "0" ] || log_info "${msg}" + else + local msg="Failed to call action '${ACTION}' on '${HNAME}' (see logs on '${HNAME}')" + [ "${SUMMARY_ONLY}" == "1" ] || log_only "Error: ${msg}" + [ "${SUMMARY_ONLY}" == "0" ] || log_error "${msg}" + exit "${rc}" + fi } usage() { @@ -172,6 +192,7 @@ case ${1:-} in --no-action-failure) export NO_ACTION_FAILURE=1; shift ; "$0" "$@" ;; --no-check-origin) export NO_CHECK_ORIGIN=1; shift ; "$0" "$@" ;; --validate) export VALIDATE=1; shift ; "$0" "$@" ;; + --summary-only) export SUMMARY_ONLY=1; shift ; "$0" "$@" ;; -h|--help|help) usage ; exit 0;; -v|--version|version) version ; exit 0;; *) usage 1; exit 1;;