Skip to content

Instantly share code, notes, and snippets.

@remyj38
Last active June 1, 2018 17:20
Show Gist options
  • Save remyj38/d3b2a8d7ec1448fe43daafde100f9f1a to your computer and use it in GitHub Desktop.
Save remyj38/d3b2a8d7ec1448fe43daafde100f9f1a to your computer and use it in GitHub Desktop.
RAID Status email report
#!/bin/bash
mdadm="/sbin/mdadm"
logfile="/tmp/raid_report.tmp"
email="your_email@your_domain.com"
subject="RAID Status Report for `hostname -f`"
drives="md0 md1"
### Set email body ###
echo "<h2>$subject</h2>" > $logfile
echo "<pre style=\"font-size:14px\">" >> $logfile
###### summary ######
(
echo ""
echo "########## RAID status report summary for all drives ##########"
echo ""
echo "+------+--------+-----+-------+-------+-------+-------+-------+-------+-------------------------+"
echo "|Device|State |Raid |Raid |Total |Active |Working|Failed |Spare |Last Update Time |"
echo "| | |Level|Devices|Devices|Devices|Devices|Devices|Devices| |"
echo "+------+--------+-----+-------+-------+-------+-------+-------+-------+-------------------------+"
) >> $logfile
for drive in $drives
do
(
$mdadm -D /dev/$drive | \
awk -v device=$drive '\
/Raid Level :/{level=$4} \
/Raid Devices :/{devices=$4} \
/Total Devices :/{total_devices=$4} \
/Update Time :/{update=$4" "$5" "$6" "$7" "$8} \
/State :/{state=$3} \
/Active Devices :/{active=$4} \
/Working Devices :/{working=$4} \
/Failed Devices :/{failed=$4} \
/Spare Devices :/{spare=$4} \
END {
printf "|%-6s|%-8s|%-5s|%7s|%7s|%7s|%7s|%7s|%7s|%-25s|\n",
device, state, level, devices, total_devices, active, working, failed, spare, \
update;
}'
) >> $logfile
done
(
echo "+------+--------+-----+-------+-------+-------+-------+-------+-------+-------------------------+"
echo ""
echo ""
) >> $logfile
###### for each drive ######
for drive in $drives
do
(
echo ""
echo "########## RAID status report for $drive drive ##########"
$mdadm -D /dev/$drive
echo ""
echo ""
) >> $logfile
done
echo "</pre>" >> $logfile
### Send report ###
cat $logfile | mail -h "Content-Type: text/html" -s "$subject" $email
rm $logfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment