From f5b8cb52583d91d1b8ac3be6845e332224dc4699 Mon Sep 17 00:00:00 2001 From: swenzel Date: Thu, 26 Jun 2025 12:50:04 +0200 Subject: [PATCH] jobutils: Sanitize return code treatment hopefully fixing a bug where the return code seems to have contained additional characters (hidden) which confused the return code analysis and provides printouts (or bash errors) like: ``` line 336: [: 0 0: integer expression expected ``` --- Utilities/Tools/jobutils2.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Utilities/Tools/jobutils2.sh b/Utilities/Tools/jobutils2.sh index eec71c33ffea5..ba96b97da090b 100644 --- a/Utilities/Tools/jobutils2.sh +++ b/Utilities/Tools/jobutils2.sh @@ -328,9 +328,14 @@ EOF # ?? should directly exit here? wait $PID || QUERY_RC_FROM_LOG="ON" - # query return code from log (seems to be safer as sometimes the wait issues "PID" not a child of this shell) - RC=$(awk '/TASK-EXIT-CODE:/{print $2}' ${logfile}) - if [ ! "${RC}" ]; then + # query return code from log and sanitize (seems to be safer as sometimes the wait issues "PID" not a child of this shell) + RC=$(awk '/TASK-EXIT-CODE:/{print $2; exit}' "${logfile}" | tr -d '[:space:]' | tr -d '\r') + if [ -z "${RC}" ]; then + RC=1 + fi + # check that RC is an integer + if ! [[ "$RC" =~ ^[0-9]+$ ]]; then + echo "Malformed TASK-EXIT-CODE: '${RC}'" RC=1 fi if [ "${RC}" -eq "0" ]; then