Last active
August 2, 2025 14:21
-
-
Save marshki/a9ed47527d8c2a44456402a05884c429 to your computer and use it in GitHub Desktop.
Use Broadcom's MegaCLI to check array's disk health.
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 | |
# | |
# disk_check | |
# | |
# Use Broadcom's MegaCLI to check array's disk health. Log results. | |
# Emit email if failed disk(s) found. | |
# | |
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu> | |
# Date: 7-JUL-2025 | |
# License: MIT | |
# --- Variables --- | |
megacli="/opt/MegaRAID/MegaCli/MegaCli64" | |
log_file="/var/log/disk_check.log" | |
email_recipients="" | |
# --- Main --- | |
host=$(hostname) | |
timestamp=$(date +"%Y-%m-%d %H:%M:%S") | |
# Check if 'MegaCLI' utility exists. Exit if not. | |
if [ ! -x "$megacli" ]; then | |
printf "%s - Error: MegaCli utility not found at %s. Exiting.\n" \ | |
"$timestamp" "$megacli" >> "$log_file" | |
exit 1 | |
fi | |
# Capture output and status of 'MegaCLI' utility. | |
megacli_output=$($megacli -showsummary -aall 2>&1) | |
megacli_status=$? | |
# Check exit status of 'megacli' utility. | |
if [ $megacli_status -ne 0 ]; then | |
printf "%s - Error: MegaCli utility failed to execute. Output: %s\n" \ | |
"$timestamp" "$megacli_output" >> "$log_file" | |
exit 1 | |
fi | |
# Check for failed disk(s) in 'MegaCLI' output. | |
if printf "%s" "$megacli_output" | grep -q 'Failed'; then | |
# Failed disk(s) found. | |
# Emit email using default handling of plain text in 'mail'. | |
printf "%s\n" "Failed disk(s) found on: $host@$timestamp." \ | |
"Replace the blinking red disk(s) in the front and/or back of the array." \ | |
"For more details, SSH to $host and run: $megacli -pdlist -aall" \ | |
| mail -s "ALERT: Failed Disk(s) on $host" "$email_recipients" | |
# Log the event. | |
printf "%s - Disk check on %s. Failed: Yes. Email sent to %s.\n" \ | |
"$timestamp" "$host" "$email_recipients" >> "$log_file" | |
else | |
# No failed disk found. | |
# Log the event. | |
printf "%s - Disk check on %s. Failed: No.\n" \ | |
"$timestamp" "$host" >> "$log_file" | |
fi | |
# Exits status 0 if disk status check completes successfully. | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment