From 7565c62b6982acd8b17c2f068afd713f8518d7d8 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Thu, 28 Oct 2021 16:15:08 +0200
Subject: [PATCH] detect -d param for smartctl

---
 check_smartstatus | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/check_smartstatus b/check_smartstatus
index 60bab33..1fd2954 100755
--- a/check_smartstatus
+++ b/check_smartstatus
@@ -19,6 +19,13 @@
 #     - [does not exist] - device does not exist in the system
 # ----------------------------------------------------------------------
 #
+# v1.3 more smartctl params - parsed in function detectParam()
+# 1st value is empty ... last one something invalid
+# PARAMS:
+# PARAMS:-d cciss,0
+# PARAMS:NO-PARAM-WAS-DETECTED
+# ----------------------------------------------------------------------
+#
 # ah=axel.hahn@iml.unibe.ch
 # ds=daniel.schueler@iml.unibe.ch
 #
@@ -28,6 +35,7 @@
 # 2020-03-05  v1.0  <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
 # 2021-01-22  v1.1  <axel.hahn@iml.unibe.ch> add status [no access]
 # 2021-04-07  v1.2  <axel.hahn@iml.unibe.ch> update message if sudo smartctl -H fails
+# 2021-10-28  v1.3  <axel.hahn@iml.unibe.ch> detect -d param for smartctl
 # ======================================================================
 
 
@@ -47,6 +55,18 @@ export PATH
 # functions
 # ----------------------------------------------------------------------
 
+function detectParam(){
+  local _mydevice=$1
+  local _moreparam
+  grep '^# PARAM' $0 | cut -f 2- -d ':' | while read _moreparam
+  do
+    sudo smartctl -H $_mydevice $_moreparam >/dev/null 2>&1 && echo "$_moreparam"
+  done
+  echo "$_moreparam"
+}
+
+# smart details for given device
+# param  string  device, i.e. /dev/sda
 function checkDrive(){
   tmpfile=/tmp/smartstatus.log
   device=$1
@@ -68,8 +88,9 @@ function checkDrive(){
     # echo >>$tmpfile
 
     # --- check health
-    # sudo smartctl -T permissive -Ha $device >>$tmpfile
-    sudo smartctl -Ha $device >>$tmpfile 2>&1
+    moreparam=$( detectParam $device )
+    echo sudo smartctl -Ha $device $moreparam >>$tmpfile 2>&1
+    sudo smartctl -Ha $device $moreparam >>$tmpfile 2>&1
     rcs=$?
     echo $device - rc=$rcs >>$tmpfile
     echo >>$tmpfile
@@ -116,7 +137,8 @@ do
 
   # on first device: check permissions
   if [ $iFound -eq 1 ]; then
-    sudo smartctl -H $mydevice >/dev/null 2>&1
+    moreparam=$( detectParam $mydevice )
+    sudo smartctl -H $mydevice $moreparam >/dev/null 2>&1
     if [ $? -ne 0 ]; then
       ph.abort "SKIP: smartctl was found - but did not respond results. Maybe no sudo permissions or additional parameters required. $( sudo smartctl -H $mydevice )"
     fi
-- 
GitLab