From b95b7b7af3e2ddaae2d0e8fafe4a34e2eb934ccc Mon Sep 17 00:00:00 2001 From: Mark Feit Date: Mon, 24 Jun 2024 18:26:52 +0000 Subject: [PATCH] Handle empty log directory correctly in 'log' command. --- pscheduler-server/pscheduler-server/utilities/log.raw | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pscheduler-server/pscheduler-server/utilities/log.raw b/pscheduler-server/pscheduler-server/utilities/log.raw index 5437c4f55c..4507935278 100755 --- a/pscheduler-server/pscheduler-server/utilities/log.raw +++ b/pscheduler-server/pscheduler-server/utilities/log.raw @@ -13,13 +13,18 @@ LOGBASE="__LOGFILE__" if [ $# -eq 0 ] then - exec cat "${LOGDIR}/${LOGBASE}" + LATEST_LOG="${LOGDIR}/${LOGBASE}" + if [ -s "${LATEST_LOG}" ] + then + exec cat "${LATEST_LOG}" + fi elif [ "$1" = "--all" ] then + # PORT: xargs -r is non-POSIX find "${LOGDIR}" -type f -name "${LOGBASE}*" -print0 \ - | xargs -0 ls -htr \ + | xargs -r -0 ls -htr \ | tr "\n" "\0" \ - | xargs -0 cat + | xargs -r -0 cat else echo "Usage: $(basename "$0") [ --all ]" exit 1