From ff8424322952eb4f12bff93b4d89d86cda9d3e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 28 Feb 2020 15:14:36 +0100 Subject: [PATCH] Manage files with variables... --- xymon/plugins/client/ext/smartoverall | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/xymon/plugins/client/ext/smartoverall b/xymon/plugins/client/ext/smartoverall index 0e41ab9..70d2f52 100755 --- a/xymon/plugins/client/ext/smartoverall +++ b/xymon/plugins/client/ext/smartoverall @@ -32,6 +32,10 @@ c_reset='\033[0m' plugin_name=$(basename "${0}") +plugin_result="/tmp/dres" +plugin_state="/tmp/dcheck" +device_list="/tmp/dscan" + # ]]] # Functions @@ -105,15 +109,15 @@ choose_correct_type() { ## ]]] # Create or empty previous files -true > /tmp/dres -true > /tmp/dcheck -true > /tmp/dscan +true > "${plugin_result}" +true > "${plugin_state}" +true > "${device_list}" # Get the list of all available devices -smartctl --scan >> /tmp/dscan +smartctl --scan >> "${device_list}" # If the file is not empty -if test -s /tmp/dscan; then +if test -s "${device_list}"; then while IFS= read -r LINE; do ## Get device path DISK=$(echo "${LINE}" | cut -d" " -f1) @@ -184,7 +188,7 @@ https://www.smartmontools.org/wiki/FAQ#SmartmontoolsDatabase" fi ## Avoid duplicate device - if ! grep -q "${DID}" /tmp/dres; then + if ! grep -q "${DID}" "${plugin_result}"; then ## For summary echo "${COLOR} $DISK ${TYPE}" @@ -200,22 +204,22 @@ https://www.smartmontools.org/wiki/FAQ#SmartmontoolsDatabase" echo "------------------------------------------------------------" echo "" echo "" - } >> /tmp/dres + } >> "${plugin_result}" fi - done < /tmp/dscan >> /tmp/dcheck + done < "${device_list}" >> "${plugin_state}" # If the file is empty else - echo "1&red Error while scanning devices with smartctl" >> /tmp/dcheck + echo "1&red Error while scanning devices with smartctl" >> "${plugin_state}" fi # Set the global color according to the highest alert -COLOR=$(< /tmp/dcheck awk '{print $1}' | sort | uniq | head -1 | cut -c3-) +COLOR=$(< "${plugin_state}" awk '{print $1}' | sort | uniq | head -1 | cut -c3-) # Send informations to Xymon server $XYMON "${XYMSRV}" "status ${MACHINE}.${plugin_name} ${COLOR} SMART health check -$(< /tmp/dcheck cut -c2-) +$(< "${plugin_state}" cut -c2-) ==================== Detailed status ==================== @@ -223,6 +227,6 @@ $(cat /tmp/dres) " # Clean temp files -rm -f -- /tmp/dres /tmp/dcheck /tmp/dscan +rm -f -- "${plugin_result}" "${plugin_state}" "${device_list}" exit 0