When using software RAID on Linux, one fast way to know the status of your RAID array is to check /proc/mdstat. If you want to setup an automated notification if the status of your RAID array changes, you can do this using the small script below.
First, you need to take a snapshot of your healthy /proc/mdstat file.
# cat /proc/mdstat > /root/mdstat
This will save the file in root’s home directory. You can save the file anywhere, but make sure user write permissions are disabled. Here is the bash script to monitor your RAID array by comparing the current status of the array against the original snapshot.
----------
#! /bin/bash
# e-mail root if there is a problem with the raid array
TO="root"
CC="address@email.com"
SUBJECT="RAID array status change on Linux server"
HEALTHYFILE=/root/mdstat
MDSTAT=/proc/mdstat
if ! diff $HEALTHYFILE $MDSTAT &>/dev/null; then
cat /proc/mdstat | mail -s "$SUBJECT" -c "$CC" $TO
fi
----------
Save the script, set it to be executable and add it to your /etc/crontab. You can run this once a day or even a few times a day, depdnign on how paranoid you are :)
If you are running Fedora, you can just drop it in your /etc/cron.daily folder and you’re good to go. If your RAID array status changes due to a drive failure, you will receive an e-mail with the contents of /proc/mdstat notifying you of the change.