Manage files with variables...
This commit is contained in:
parent
4d90168df5
commit
ff84243229
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue