diff --git a/check_smartarray.sh b/check_smartarray.sh index 936592a..d2a0362 100644 --- a/check_smartarray.sh +++ b/check_smartarray.sh @@ -3,29 +3,29 @@ # Written by: Søren Klintrup # Get your copy from: https://github.com/Klintrup/check_smartarray/ +unset ERRORSTRING +unset OKSTRING +unset ERR + PATH="/sbin:/bin:/usr/sbin:/usr/bin" if [ -x "/sbin/camcontrol" ] then - DEVICES="$(camcontrol devlist|egrep "(HP|COMPAQ) RAID"|sed -Ee 's/.*(pass[0-9]{1,3}).*/\1/')" + DEVICES="$(camcontrol devlist|grep -Ee "(HP|COMPAQ) RAID"|sed -Ee 's/.*(pass[0-9]{1,3}).*/\1/')" else ERRORSTRING="camcontrol binary does not exist on system" ERR=3 fi -unset ERRORSTRING -unset OKSTRING -unset ERR - for DEVICE in ${DEVICES} do DEVICENAME="$(camcontrol devlist|grep ${DEVICE}|sed -Ee 's/.*(da[0-9]{1,3}).*/\1/')" DEVICESTRING="$(camcontrol inquiry ${DEVICE} -D|sed -n -e 's/^[^<]*<\([^>]*\)>.*$/\1/p')" - if [ "$(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/')" = "" ] + if [ "$(echo ${DEVICESTRING}|tr '[:upper:]' '[:lower:]'|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/')" = "" ] then ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: unknown state" if ! [ "${ERR}" = 2 ];then ERR=3;fi else - case $(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/') in + case $(echo ${DEVICESTRING}|tr '[:upper:]' '[:lower:]'|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/') in int) ERR=2 ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: DEGRADED" @@ -35,15 +35,15 @@ do ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: FAILED" ;; rec) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: rebuilding" ;; exp) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: expanding" ;; rea) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: ready for recovery" ;; ok) @@ -57,10 +57,10 @@ if [ "${1}" ] then if [ "${ERRORSTRING}" ] then - echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "//|mail -s "$(hostname -s): ${0} reports errors" -E ${*} + echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "//|mail -s "$(hostname -s): ${0} reports errors" -E "${@}" fi else -if [ "${ERRORSTRING}" -o "${OKSTRING}" ] +if [ "${ERRORSTRING}" ] || [ "${OKSTRING}" ] then echo ${ERRORSTRING} ${OKSTRING}|sed s/"^\/ "// exit ${ERR}