From 6e26d97df7ee48880255dc3ec91e34128bfd2fb1 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchuk Date: Wed, 23 Oct 2024 15:53:06 +0300 Subject: [PATCH] Removing extra shell command; Use bash builtin for extracting a substring (#221) Removing extra shell command; Use bash builtin for extracting a substring Signed-off-by: Mykhailo Kravchuk --- smartmon.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/smartmon.sh b/smartmon.sh index bd70b37..d9f12d7 100755 --- a/smartmon.sh +++ b/smartmon.sh @@ -167,12 +167,13 @@ format_output() { awk -F'{' "${output_format_awk}" } -smartctl_version="$(/usr/sbin/smartctl -V | head -n1 | awk '$1 == "smartctl" {print $2}')" +smartctl_version="$(/usr/sbin/smartctl -V | awk 'NR==1 && $1 == "smartctl" {print $2}')" echo "smartctl_version{version=\"${smartctl_version}\"} 1" | format_output -if [[ "$(expr "${smartctl_version}" : '\([0-9]*\)\..*')" -lt 6 ]]; then - exit +# Exit if "smartctl" version is lower 6 +if [[ ${smartctl_version%.*} -lt 6 ]]; then + exit 0 fi device_list="$(/usr/sbin/smartctl --scan-open | awk '/^\/dev/{print $1 "|" $3}')"