Manage case of an empty file with smartctl results
This commit is contained in:
parent
fb1094308d
commit
b05d10771c
|
@ -27,25 +27,28 @@ 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}."
|
||||
|
||||
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
|
||||
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
||||
|
||||
## TODO: Test if grep successfully got something
|
||||
|
||||
## Parse all "support" lines
|
||||
while IFS= read -r _LINE; do
|
||||
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
||||
then
|
||||
smart_support_msg="${_LINE}"
|
||||
fi
|
||||
done < "${_smarctl_support_result}"
|
||||
## If the file is not empty
|
||||
if test -s "${_smarctl_support_result}"; then
|
||||
## Parse all "support" lines
|
||||
while IFS= read -r _LINE; do
|
||||
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
||||
then
|
||||
smart_support_msg="${_LINE}"
|
||||
fi
|
||||
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
|
||||
[ "${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
|
||||
[ "${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
|
||||
|
||||
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/dscan; then rm -f /tmp/dscan; fi
|
||||
if test -f /tmp/dres; then rm -f -- /tmp/dres; fi
|
||||
if test -f /tmp/dscan; then rm -f -- /tmp/dscan; fi
|
||||
|
||||
# Get the list of all available devices
|
||||
smartctl --scan > /tmp/dscan
|
||||
|
@ -144,6 +147,6 @@ $(< /tmp/dcheck cut -c2-)
|
|||
$(cat /tmp/dres)
|
||||
"
|
||||
|
||||
rm -f /tmp/dres /tmp/dcheck /tmp/dscan
|
||||
rm -f -- /tmp/dres /tmp/dcheck /tmp/dscan
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue