Is there a way to automate the disk failure
   notification (eg, to send mail to the sys admin)?

I have this script called from cron every 5 minutes with an entry like
this: 

*/5 * * * * checkmd -v

If checkmd fails, cron generates a mail message to the owner of the cron
script. 

------------ checkmd -------------
#! /bin/bash
#
# This script checks that the md configuration is the same as that
# read at configuration time.  When called with the -i option, it
# reads /proc/mdstat and learns the configuration.  If called without
# args, it returns non zero status if the configuration is different
# from the one learned, and prints a message if the -v flag is present.
#
# usage: checkmd.sh [-iv]

init=""
verbose=""
CONF=/etc/md.conf

while getopts "iv" opt; do case $opt in
    i)
        init=true
        ;;
    v)
        verbose=true
        ;;
    *)
        cat <<-EOF
        usage: $0 [-iv] [fromdev] [todev]
            -i means init the file $CONF with the current md configuration
            -v means display a message in case of configuration mismatch
        EOF
        exit 1
        ;;
esac; done

if [ ! -r $CONF -o "$init" = true ]; then
    cat /proc/mdstat > $CONF
    chmod 444 $CONF
    echo "Current configuration saved in $CONF:" >&2
    cat $CONF >&2
else
    cat /proc/mdstat | cmp $CONF >/dev/null
    if [ $? != 0 ]; then
        if [ $verbose ]; then
            echo >&2
            echo "ALARM! md configuration problem" >&2
            echo >&2
            echo "Current configuration is:" >&2
            cat /proc/mdstat >&2
            echo >&2
            echo "should be:" >&2
            cat $CONF >&2
        fi
    exit 1
    fi
fi

Reply via email to