Last active
June 25, 2025 13:41
-
-
Save gchamon/4081ff08c92bdf4ab2822d00c03d2c9f to your computer and use it in GitHub Desktop.
MDADM report generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
REPORT_FOLDER=/tmp/mdadm-report | |
REPORT_FILE=/tmp/mdadm-report.txt | |
MD_ARRAY=$(cat /proc/mdstat | grep -o 'md[0-9]\+') | |
ARRAY_DEVICES=$(lsblk --json | jq --arg md_array "$MD_ARRAY" -r '.blockdevices[] | select(.children[0].name == $md_array) | .name') | |
rm -rf $REPORT_FOLDER $REPORT_FILE | |
mkdir -p $REPORT_FOLDER | |
sudo mdadm --detail /dev/$MD_ARRAY >"$REPORT_FOLDER"/"$MD_ARRAY"-detail.txt | |
for device in $ARRAY_DEVICES; do | |
sudo smartctl -a /dev/$device >"$REPORT_FOLDER/smartctl-$(basename $device)" | |
done | |
more $REPORT_FOLDER/* >$REPORT_FILE | |
echo report generated at $REPORT_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment