#!/bin/sh # Author: Adam Cécile <acecile@mandriva.com> # License: GNU General Public License v2 or later # # Based on work by Petter Reinholdtsen <pere@hungry.com> # In Debian's package "mpt-status" PATH=/sbin:/bin:/usr/sbin:/usr/bin STATUSFILE=/var/run/megasasctl.status MAILTO=root # Where to report problems (default root) REMIND=7200 # Seconds between each reminder (default 2 hours) . /etc/megactl/megasasctl-cron.conf # One line for each broken thing in silent mode if [ `megasasctl -H $PARAMS | wc -l` -eq 0 ]; then BADRAID=false else BADRAID=true logger -t MegaSASCTL "Detected non-optimal RAID status" fi STATUSCHANGE=false if [ true = "$BADRAID" ] ; then # RAID not OK (megasasctl $PARAMS) > $STATUSFILE.new if [ ! -f $STATUSFILE ] ; then # RAID just became broken STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE elif cmp -s $STATUSFILE $STATUSFILE.new ; then # No change. Should we send reminder? LASTTIME="`stat -c '%Z' $STATUSFILE`" NOW="`date +%s`" SINCELAST="`expr $NOW - $LASTTIME`" if [ $REMIND -le "$SINCELAST" ]; then # Time to send reminder STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE else rm $STATUSFILE.new fi else STATUSCHANGE=true mv $STATUSFILE.new $STATUSFILE fi else # RAID OK if [ -f $STATUSFILE ] ; then rm $STATUSFILE STATUSCHANGE=true fi fi if [ true = "$STATUSCHANGE" ]; then hostname="`uname -n`" ( cat <<EOF This is a RAID status update from MegaSASCTL. The MegaSASCTL program reports that one of the RAIDs changed state: EOF if [ -f $STATUSFILE ] ; then cat $STATUSFILE else (megasasctl $PARAMS) fi echo echo "Report from MegaSASCTL on $hostname" ) | mail -s "info: MegaSASCTL raid status change on $hostname" $MAILTO fi