I have a script that keeps unsetting the value but I cant find why. In the case below the output is:
green Physical drive in slot 2I:1:1 (size : 146.8GB) status is OK
green Physical drive in slot 2I:1:2 (size : 146.8GB) status is OK
green Physical drive in slot 2I:1:3 (size : 146.8GB) status is OK
yellow Physical drive in slot 2I:1:4 (size : 146.8GB) status is BAD !!!
green Physical drive in slot 2I:1:5 (size : 146.8GB) status is OK
I need the value Yellow to trigger my monitor. But yellow is changed in the loop and I can't find what I'm doing wrong
$HPACUCLI ctrl all show config | grep drive | while read OUTPUT ; do
TYPE=$(echo $OUTPUT | awk '{print $1}' | sed s/drive//)
SLOT=$(echo $OUTPUT | awk '{print $2}')
STATUS=$(echo $OUTPUT | awk '{print $NF}' | sed s/\)//)
if [ "$STATUS" == "spare" ] ; then
STATUS=$(echo $OUTPUT | cut -d',' -f4 | sed 's/ //g')
fi
if [ "$TYPE" == "physical" ] ; then
SIZE=$(echo $OUTPUT | awk '{print $8 $9}' | sed s/\,//)
if [ "$STATUS" != "OK" ] ; then
YELLOW=1
echo "Yellow" "$YELLOW"
LINE="&yellow Physical drive in slot $SLOT (size : $SIZE) status is BAD !!!"
elif [ "$STATUS" == "OK" ] ; then
echo "Yellow" "$YELLOW"
LINE="&green Physical drive in slot $SLOT (size : $SIZE) status is OK"
else
echo "Yellow" "$YELLOW"
RED=1
LINE="&red Unknow status (or stupid monitoring script) for physical drive in slot $SLOT \(size : $SIZE\) !!!"
fi
fi
echo $LINE >> $MSG_FILE
done
echo "Yellow" "$YELLOW"
The output when running is:
Yellow
Yellow
Yellow
Yellow 1
Yellow 1
Yellow
Why is the last Yellow not 1 ??