Monitor Linux software RAID array with e-mail notification

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

SUBJECT="RAID array status change on Linux server"

if ! diff $HEALTHYFILE $MDSTAT &>/dev/null; then
cat /proc/mdstat | mail -s "$SUBJECT" -c "$CC" $TO


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.

  • 10 Users Found This Useful
Was this answer helpful?

Related Articles

How to change the target of a symbolic link

To change the target of a symbolic link in linux, you can use the following command. ln -f -s...

Changing permissions on directories only

You may need to change permissions for directories under a directory tree, without changing...

Searching for files containing a specific text string in Linux

The find and locate commands are great for finding files themselves, but sometimes you need to...

Powered by WHMCompleteSolution