The following is a simple script to monitor a Software Raid configuration on a Linux System.
It execute a /proc/mdstat check to search a ‘blocks_’ occurency which indicates problems on the Raid system and in case of match it notify the system administrator with a mail message.
It should be very useful for non-presidiated system, even if I always prefer Hardware Raid.
#!/bin/bash # # Script created by Riccardo Riva # http://www.riccardoriva.com # # It check a Software Raid subsystem and notify by mail any occurency problem # Define variable LOG_FILE=/tmp/raid-check.log SYSTEM=`uname --nodename` MAILTO='systemadmin@mail.exp' # Checking /proc/mdstat cat /proc/mdstat | grep 'blocks.*_' > $LOG_FILE # Define function in case of problems detected if [ $? -eq 0 ] then echo "The $SYSTEM system has RAID failures on it." >> $LOG_FILE echo "Below is the output from /proc/mdstat" >> $LOG_FILE echo "===========================================" >> $LOG_FILE cat /proc/mdstat >> $LOG_FILE echo "===========================================" >> $LOG_FILE cat $LOG_FILE | mail -s 'URGENT: RAID disk failure detected' $MAILTO fi # Deleting log file rm -f >> $LOG_FILE # Exit exit 0
Save the file above as /usr/local/bin/raidcheck.sh and assign to it correct permission and ownership with the folowing :
chmod 700 /usr/local/bin/raidcheck.sh chown root:nobody /usr/local/bin/raidcheck.sh
Change the email address variable with a real email address who will receive the notification.
You should now schedule the script execution at every time interval you want (i.e. twice a day, or hourly if you are paranoic).
Remember that is better to be paranoic that have a degraded system with unrecoverable data.
Hope this help
Bye
Riccardo
Print This Post























