Category: sysadmin utilities
Author/Contact Info Artem Litvinovich
Description: raidwatch README. Author: Artem Litvinovich Raidwatch should be run as a cron job. It monitors the /proc/mdstat file for the status of your software raid array. The specified contact is notified if a problem occurs with one or more disks in the array.
#!/bin/sh
# RaidWatch utility by Artem Litvinovich
RAID_ADMIN="admin@yourdomain.com"
RAID_HOST=`/bin/hostname`
CUR_DATE=`/bin/date +\%Y.\%m.\%d-\%H:\%M`
test -n "`perl -ne '/ \[(\d)\/(\d)\] / && $2 ne $1 && print "X";' /pro
+c/mdstat`" && \
/bin/mail -s "RAID disk failure on $RAID_HOST ($CUR_DATE)" $RAID_ADMIN
+ < /proc/mdstat
Replies are listed 'Best First'.
Re: raid array checker (mdstat)
by Aristotle (Chancellor) on Mar 01, 2003 at 15:45 UTC
    Ugh.
    #!/usr/bin/perl -w use POSIX qw(strftime); my $raid_admin = "root@foo.bar"; my $raid_host = `/bin/hostname`; @ARGV = qw(/proc/mdstat); my @mdstat = <>; ## UNTESTED exit if not grep m{ \[(\d)/(\d)\] } && $1 ne $2, @mdstat; open( my $mail, "|/bin/mail -s 'RAID disk failure on $raid_host (". strftime('%Y.%m.%d-%H:%M'). ")' $raid_admin" ) or die "Couldn't spawn /bin/mail: $!\n"; print $mail @mdstat; close $mail;
    Something along these lines if you're gonna do it in Perl.

    Makeshifts last the longest.