From a6245d21a0ce955962f5a994d3274a267cda7701 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Sun, 9 Feb 2020 16:47:24 +0100 Subject: [PATCH] Better handling of output of 'wc' --- check_rebootrequired.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/check_rebootrequired.sh b/check_rebootrequired.sh index a497687..acd7cc2 100755 --- a/check_rebootrequired.sh +++ b/check_rebootrequired.sh @@ -6,8 +6,28 @@ if [ ! -f "$INPUT" ]; then fi NUM_LINES=`cat "$INPUT" | wc -l` -echo "WARNING: $NUM_LINES packages require a reboot:" -cat "$INPUT" -exit 1 +case $NUM_LINES in + 0) + echo "UNKNOWN: $INPUT is empty" + exit 4 + ;; + 1) + echo "WARNING: $NUM_LINES package requires a reboot:" + cat "$INPUT" + exit 1 + ;; + [2-9]*) + echo "WARNING: $NUM_LINES packages require a reboot:" + cat "$INPUT" + exit 1 + ;; + *) + echo "UNKNOWN: Unexpected output of 'wc': $NUM_LINES" + exit 4 + ;; + +esac + +