#!/bin/bash # mdadm --monitor event handler, by Jan Ceuleers # Licence: GPL v2 # Handles SparesMissing event. Uses blkid output to find devices that have # the same UUID as the RAID device, but which are not yet members of the array. # Have this script executed by mdadm by passing its name to the mdadm --monitor # daemon using the --program parameter. # On Debian-like systems this can be accomplished like so: # echo "DAEMON_OPTIONS=\"\$DAEMON_OPTIONS --program /pathto/script\"" >> /etc/default/mdadm BLKID="/sbin/blkid" MDADM="/sbin/mdadm" ( case $1 in SparesMissing) COMPUUID=`$MDADM -D $2 | grep UUID | cut -f 2 -d 'D' | cut -f 3 -d ' '` COMPUUID2=${COMPUUID//:/} COMPUUID3=${COMPUUID2:0:8}-${COMPUUID2:8:4}-${COMPUUID2:12:4}-${COMPUUID2:16:4}-${COMPUUID2:20} echo The UUID of component devices is $COMPUUID \($COMPUUID3\) blkid | grep $COMPUUID3 | grep linux_raid_member | ( while read l; do COMPDEV=`echo $l | cut -f 1 -d ':'` $MDADM -D $2 | grep $COMPDEV > /dev/null if [ $? -eq 0 ] ; then echo Device $COMPDEV is already a member of the array else echo Found device $COMPDEV with the same UUID but not yet a component device. $MDADM $2 --add $COMPDEV 2>&1 fi done ) ;; *) echo "Unknown event type; can't handle." ;; esac ) | mail -s "Handling $1 mdadm event on $2" root