I wanted a simple check to email me should my software RAID die on a server. Originally I started writing a simple ruby script based on a Perl script I found somewhere online (_gmirror status_ has a very nice -s switch for a script friendly output). Then I realised that I could probably do what I wanted just as well with a one liner in my crontab and save myself the overhead of spawning the Ruby/Perl processor.
This is what I came up with:
/sbin/gmirror status | grep -q 'COMPLETE'; if [ "$?" -ne "0" ]; then /sbin/gmirror status | mail -s "Raid Mirror" "panic@example.com"; fi
Whack that in a crontab with a suitable email address and away you go.
Essentially we are doing a quiet grep on the output of the gmirror status command, looking for the keyword complete:
/sbin/gmirror status | grep -q 'COMPLETE';
We then check the exit condition (given to us by the $?
) of the grep:
if [ "$?" -ne "0" ]; then ... fi
If the grep found nothing (_i.e._ out RAID is no longer complete) we send the output of gmirror status to the email address using the normal *NIX mail command.
/sbin/gmirror status | mail -s "Raid Mirror" "panic@example.com"
Does the trick nicely!
Written on 08 Jun 2010 and categorised in FreeBSD, tagged as email, RAID, Geom, and crontab