Last active
March 17, 2025 17:48
-
-
Save marshki/a9ed47527d8c2a44456402a05884c429 to your computer and use it in GitHub Desktop.
Bash check for Offlne (Onln=Online|Offln=Offline) disk using 'storecli' and 'awk' on MegaRAID controller cards.
This file contains 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 | |
# | |
# Emit email to: '' if failed disk(s) found on array | |
# | |
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu> | |
# Date: 22-Feb-2022 | |
# License: MIT | |
megacli="/opt/MegaRAID/MegaCli/MegaCli64" | |
date="$(date +'%b %d %Y %X')" | |
host="$(hostname)" | |
recipients="" | |
log_file="/var/log/disk_check.log" | |
# Check if call to megacli succeeds | |
if ! $megacli -showsummary -aall >/dev/null 2>&1; then | |
printf "%s\n" "$(date +"%Y-%m-%d %H:%M:%S") - Error: MegaCli failed to execute." >&2 | |
exit 1 | |
fi | |
# Parse megacli call & emit email if failure detected | |
if $megacli -showsummary -aall | grep -q Failed; then | |
printf "%s\n" "Failed disk(s) found on: $host@$date." "Replace the blinking red disk(s) in the front and/or back of the array." | | |
mail -s "Failed Disk@$host" "$recipients" | |
printf "%s\n" "$(date +"%Y-%m-%d %H:%M:%S") - Disk check on $host. Failed: Yes" >> "$log_file" | |
else | |
printf "%s\n" "No failed disk(s) found on: $host@$date. Exiting." | |
printf "%s\n" "$(date +"%Y-%m-%d %H:%M:%S") - Disk check on $host. Failed: No" >> "$log_file" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment