Manage case of an empty file with smartctl results
This commit is contained in:
parent
fb1094308d
commit
b05d10771c
|
@ -27,13 +27,13 @@ is_disk_support_smart() {
|
||||||
|
|
||||||
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − check if SMART is supported on : ${_disk}."
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − check if SMART is supported on : ${_disk}."
|
||||||
|
|
||||||
if test -f "${_smarctl_support_result}"; then rm -f "${_smarctl_support_result}"; fi
|
if test -f "${_smarctl_support_result}"; then rm -f -- "${_smarctl_support_result}"; fi
|
||||||
|
|
||||||
## Grep only "support" lines from disk's informations
|
## Grep only "support" lines from disk's informations
|
||||||
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
||||||
|
|
||||||
## TODO: Test if grep successfully got something
|
## If the file is not empty
|
||||||
|
if test -s "${_smarctl_support_result}"; then
|
||||||
## Parse all "support" lines
|
## Parse all "support" lines
|
||||||
while IFS= read -r _LINE; do
|
while IFS= read -r _LINE; do
|
||||||
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
||||||
|
@ -41,11 +41,14 @@ is_disk_support_smart() {
|
||||||
smart_support_msg="${_LINE}"
|
smart_support_msg="${_LINE}"
|
||||||
fi
|
fi
|
||||||
done < "${_smarctl_support_result}"
|
done < "${_smarctl_support_result}"
|
||||||
|
else
|
||||||
|
smart_support_msg="smartctl was not able to open ${_disk} DEVICE with ${_type} TYPE."
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "${smart_support_msg}" ]; then
|
if [ -z "${smart_support_msg}" ]; then
|
||||||
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART seems fully supported on : ${_disk}."
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART seems fully supported on : ${_disk} with ${_type} type."
|
||||||
else
|
else
|
||||||
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART is not fully supported on : ${_disk}. See smartctl informations :\n${smart_support_msg}"
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART is not fully supported on : ${_disk} with ${_type} type. See smartctl informations :\n${smart_support_msg}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f -- "${_smarctl_support_result}"
|
rm -f -- "${_smarctl_support_result}"
|
||||||
|
@ -77,8 +80,8 @@ choose_correct_type() {
|
||||||
}
|
}
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
if test -f /tmp/dres; then rm -f /tmp/dres; fi
|
if test -f /tmp/dres; then rm -f -- /tmp/dres; fi
|
||||||
if test -f /tmp/dscan; then rm -f /tmp/dscan; fi
|
if test -f /tmp/dscan; then rm -f -- /tmp/dscan; fi
|
||||||
|
|
||||||
# Get the list of all available devices
|
# Get the list of all available devices
|
||||||
smartctl --scan > /tmp/dscan
|
smartctl --scan > /tmp/dscan
|
||||||
|
@ -144,6 +147,6 @@ $(< /tmp/dcheck cut -c2-)
|
||||||
$(cat /tmp/dres)
|
$(cat /tmp/dres)
|
||||||
"
|
"
|
||||||
|
|
||||||
rm -f /tmp/dres /tmp/dcheck /tmp/dscan
|
rm -f -- /tmp/dres /tmp/dcheck /tmp/dscan
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue