Skip to content

Commit cc7a23d

Browse files
committed
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 ```
1 parent aa1ca7a commit cc7a23d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Utilities/Tools/jobutils2.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,14 @@ EOF
328328
# ?? should directly exit here?
329329
wait $PID || QUERY_RC_FROM_LOG="ON"
330330

331-
# query return code from log (seems to be safer as sometimes the wait issues "PID" not a child of this shell)
332-
RC=$(awk '/TASK-EXIT-CODE:/{print $2}' ${logfile})
333-
if [ ! "${RC}" ]; then
331+
# query return code from log and sanitize (seems to be safer as sometimes the wait issues "PID" not a child of this shell)
332+
RC=$(awk '/TASK-EXIT-CODE:/{print $2; exit}' "${logfile}" | tr -d '[:space:]' | tr -d '\r')
333+
if [ -z "${RC}" ]; then
334+
RC=1
335+
fi
336+
# check that RC is an integer
337+
if ! [[ "$RC" =~ ^[0-9]+$ ]]; then
338+
echo "Malformed TASK-EXIT-CODE: '${RC}'"
334339
RC=1
335340
fi
336341
if [ "${RC}" -eq "0" ]; then

0 commit comments

Comments
 (0)