Skip to content

Instantly share code, notes, and snippets.

@gchamon
Last active June 25, 2025 13:41
Show Gist options
  • Save gchamon/4081ff08c92bdf4ab2822d00c03d2c9f to your computer and use it in GitHub Desktop.
Save gchamon/4081ff08c92bdf4ab2822d00c03d2c9f to your computer and use it in GitHub Desktop.
MDADM report generation
#!/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