Wrote a script to turn on LED on disk failure, needs review/testing

Status
Not open for further replies.

Ender117

Patron
Joined
Aug 20, 2018
Messages
219
Inspired by this thread, I wrote (shamelessly copying) a script using sesutil. First time try scripting but looks pretty straightforward to me. Tried on my system and looks like it worked. What's your thought on this? If you tried it on your system, let me know how it worked

Code:
if [ ! "$1" ]; then
  echo "Usage: faildediskled.sh [pool] "
  echo "Scan a pool, activate leds of failed drives"
  exit
fi
pool="$1"

condition=$(/sbin/zpool status $pool | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')

if [ "${condition}" ]; then


echo "Pool unhealthy, scanning for failed drive(s)."

glabel status | awk '{print "s|"$1"|"$3"\t\t\t	  |g"}' > /tmp/glabel-lookup.sed

zpool status $pool | grep -vE "(REMOVED|$pool)" | awk -F'was /dev/' '{print $2}' |  sed -f /tmp/glabel-lookup.sed | awk -F'p[0-9]' '{print $1}' | awk 'NF' >> /tmp/faileddisk.sed

zpool status $pool | grep -E "(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED)" | grep -vE "($pool|NAME|mirror|raidz|stripe|logs|spares|state|was /dev/)" |awk -F'(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED)' '{print $1}' |  sed -f /tmp/glabel-lookup.sed | awk -F'p[0-9]' '{print $1}' | awk 'NF' >> /tmp/faileddisk.sed

#cat /tmp/faileddisk.sed

sesutil locate all off > /dev/null 2>&1

for faileddisk in $(cat /tmp/faileddisk.sed);
do
	echo $faileddisk "failed, trying to blink LED."
	sesutil locate $faileddisk on

done

rm /tmp/glabel-lookup.sed
rm /tmp/faileddisk.sed

else

echo "Pool healthy, turning off all LEDs."
sesutil locate all off > /dev/null 2>&1


fi
 
Last edited:

Ender117

Patron
Joined
Aug 20, 2018
Messages
219
Don't have a faulted system to test it on, but I'll give it a shot when I do. Good Resource potential!

I don't either, and I wish I never will :p

I also made some changes so it can be used with multiple pools
Code:
if [ ! "$1" ]; then
  echo "Usage: faildediskled.sh [pool1] [pool2] [pool3] ..."
  echo "Scan the specified pool(s), activate LEDs of failed drive(s)"
  exit
fi

echo "Checking" $# "pool(s)"

allpool="$@"

globalcondition=$(/sbin/zpool status $allpool | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')

if [ "${globalcondition}" ]; then
glabel status | awk '{print "s|"$1"|"$3"\t\t\t	  |g"}' > /tmp/glabel-lookup.sed
echo $@|tr " " "\n" > /tmp/poolstoscan.sed
sesutil locate all off > /dev/null 2>&1

for pool in $(cat /tmp/poolstoscan.sed);
do

condition=$(/sbin/zpool status $pool | egrep -i '(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover)')

if [ "${condition}" ]; then

echo $pool "is unhealthy, scanning for failed drive(s)."

zpool status $pool | grep -vE "(REMOVED|$pool)" | awk -F'was /dev/' '{print $2}' |  sed -f /tmp/glabel-lookup.sed | awk -F'p[0-9]' '{print $1}' | awk 'NF' >> /tmp/faileddisk.sed
zpool status $pool | grep -E "(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED)" | grep -vE "($pool|NAME|mirror|raidz|stripe|logs|spares|state|was /dev/)" |awk -F'(DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED)' '{print $1}' | sed -f /tmp/glabel-lookup.sed | awk -F'p[0-9]' '{print $1}' | awk 'NF' >> /tmp/faileddisk.sed


for faileddisk in $(cat /tmp/faileddisk.sed);
do
	echo $faileddisk "failed, trying to blink LED."
	sesutil locate $faileddisk on
done

rm /tmp/faileddisk.sed

else
echo $pool "is healthy, checking next pool."

fi

done

rm /tmp/glabel-lookup.sed
rm /tmp/poolstoscan.sed

else


echo "All pool(s) are healthy, turning off all LEDs."
sesutil locate all off > /dev/null 2>&1


fi

 
Status
Not open for further replies.
Top