Add a function to test SMART support on a disk
This commit is contained in:
parent
cbf0d8afb0
commit
26d6b06c86
|
@ -2,6 +2,55 @@
|
||||||
|
|
||||||
# NOTE: Must be run as root, so you probably need to setup sudo for this.
|
# NOTE: Must be run as root, so you probably need to setup sudo for this.
|
||||||
|
|
||||||
|
# Vars {{{
|
||||||
|
debug="0"
|
||||||
|
|
||||||
|
## Colors {{{
|
||||||
|
c_redb='\033[1;31m'
|
||||||
|
c_magentab='\033[1;35m'
|
||||||
|
c_reset='\033[0m'
|
||||||
|
## }}}
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
## Test if a disk really support SMART {{{
|
||||||
|
## Smartctl can give an health status even without a full support
|
||||||
|
## of SMART for some type (eg. scsi or megaraid).
|
||||||
|
## Exemple : SMART support is: Unavailable - device lacks SMART capability.
|
||||||
|
is_disk_support_smart() {
|
||||||
|
_disk="${1}"
|
||||||
|
_type="${2}"
|
||||||
|
|
||||||
|
_smarctl_support_result="/tmp/dsupport.$(basename "${_disk}")"
|
||||||
|
|
||||||
|
smart_support_msg=""
|
||||||
|
|
||||||
|
[ "${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
|
||||||
|
|
||||||
|
## Get only "support" lines from disk's informations
|
||||||
|
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
||||||
|
|
||||||
|
## 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 [ -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}."
|
||||||
|
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}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f -- "${_smarctl_support_result}"
|
||||||
|
}
|
||||||
|
## }}}
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -13,6 +62,8 @@ while IFS= read -r LINE; do
|
||||||
DISK=$(echo "${LINE}" | cut -d" " -f1)
|
DISK=$(echo "${LINE}" | cut -d" " -f1)
|
||||||
TYPE=$(echo "${LINE}" | cut -d" " -f3)
|
TYPE=$(echo "${LINE}" | cut -d" " -f3)
|
||||||
|
|
||||||
|
is_disk_support_smart "${DISK}" "${TYPE}"
|
||||||
|
|
||||||
## Get SMART Health Status and return code
|
## Get SMART Health Status and return code
|
||||||
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
|
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
|
||||||
DCODE=$?
|
DCODE=$?
|
||||||
|
|
Loading…
Reference in New Issue