From 2502f8c8177378c74133e515312ba0e5cb695939 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Wed, 2 Aug 2023 16:13:58 +0200 Subject: [PATCH] Refactor temperature check and error handling - Refactored code to improve readability and maintainability - Added error handling for when Temper USB is not found - Updated variable names for clarity --- check-env-temp.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/check-env-temp.sh b/check-env-temp.sh index 4fc0d5d..acc2d97 100644 --- a/check-env-temp.sh +++ b/check-env-temp.sh @@ -89,7 +89,13 @@ script_name=$(basename "${0}") script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) GetOptions "$@" -val=$(temper --json | jq '.[0]."internal temperature"' | bc -l) +json=$(temper --json) +if [[ ${json} == '[]' ]]; then + echo "MEMORY UNKNOWN - Temper USB not found" + exit 3 +fi + +val=$(echo ${json} | jq '.[0]."internal temperature"' | bc -l) if (( $(echo "$val < ${critmin}" | bc -l) )); then rval=2