Check the status of RAIDs, and send an email if problem
[root@linux02 scripts]# cat check_raid_disks_status.sh
#!/bin/bash #set -x #==================================================================== #@(#) Check RAID disks into SuperMicro SuperServers #==================================================================== # version 1.0 Manu dir=`dirname $0` . $dir/.env HOSTNAME=$(hostname -s) logfile=$logpath/check_raid_disks.txt tsmemailsender="root.${HOSTNAME}@mydom.lu" #--------------------------- check_megaraid() { # /opt/MegaRAID/storcli/storcli64 show --> package from https://www.broadcom.com for adapter in /c0 /c1 do /opt/MegaRAID/storcli/storcli64 ${adapter} show | egrep "RAID|DRIVE|SATA" | egrep -v "^Product|^Current" | grep -v 'Onln' | grep -v 'Optl' /opt/MegaRAID/storcli/storcli64 ${adapter} show | egrep "RAID|DRIVE|SATA" >> $logname 2>&1 done } #--------------------------- check_intelraid() { # The configuration is done into the BIOS for device in /dev/md124 /dev/md126 do if [ -e ${device} ] then mdadm --detail ${device} | egrep "State|/dev/sd" | grep -v "RaidDevice" | grep -v 'active' mdadm --detail ${device} | egrep "State|/dev/sd" >> $logname 2>&1 fi done } #--------------------------- main () { date "+%d-%m-%Y %H:%M" echo "# Check megaraid" check_megaraid > $logfile echo "# Check intelraid" check_intelraid >> $logfile echo "#####################################" if [ -s $logfile ] then echo "ERROR in the raid config on server $HOSTNAME" cat >> $logfile << EOF ################################## Check using the commands: /opt/MegaRAID/storcli/storcli64 /c0 show /opt/MegaRAID/storcli/storcli64 /c1 show mdadm --detail /dev/md124 mdadm --detail /dev/md126 EOF subject="ERROR in the RAID config on server $HOSTNAME" echo "Script name: $sn" | mailx -a "$logfile" -r "$tsmemailsender" -s "$subject" $destination else echo "RAID disks on server $HOSTNAME is OK" fi } main > $logname 2>&1