web analytics

Software raid monitoring script

You wake up one day and realize that your site is dead. You try to reboot your server, nothing happens, your hard disk is gone 🙁 🙁

You wish if there was an alert to notify of the disk problem. See a sample script below with software raid which will alert you when disk fails.

#!/bin/sh

TO=”abc@123.com”

CC=”def@123.com”

#Suppose there are two raid arrays md1 and md3

CONTENT=`/sbin/mdadm –detail /dev/md3 ; /sbin/mdadm –detail /dev/md1`

COMPARE_md3=`/sbin/mdadm –detail /dev/md3 | grep “State :” | awk -F’:’ ‘{ print $2 }’`
COMPARE_md1=`/sbin/mdadm –detail /dev/md1 | grep “State :” | awk -F’:’ ‘{ print $2 }’`

if [[ ( $COMPARE_md3 = ” clean ” || $COMPARE_md3 = ” active ” || $COMPARE_md3 = “clean, checking” || $COMPARE_md3 = “active, checking” &&  $COMPARE_md1 = ” clean ” ||  $COMPARE_md1 = ” active ”  ||  $COMPARE_md1 = ” clean, checking ” ||  $COMPARE_md1 = ” active, checking ” ) ]]

then
SUBJECT=”RAID Check OK ”
echo  “$CONTENT”| /bin/mail -s “$SUBJECT” “$TO” “$CC”
else
SUBJECT=”URGENT – Suspected failed drive”
echo “$CONTENT” | /bin/mail -s “$SUBJECT” “$TO” “$CC”
fi

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>