#/bin/bash # Errors to look for NON_ERROR_FILTER="Drive has flagged a S.M.A.R.T alert : No|Device\(Encl-[0-9][0-9]? Slot-[0-9][0-9]?\) is not in rebuild process|Foreign State: None|Inquiry Data:|Firmware state: Online, Spun Up|Raw Size:|PD Type:|Drive's position:.*DiskGroup: [0-9][0-9]?, Span: [0-9][0-9]?, Arm: [0-9][0-9]?|Physical Disk: [0-9][0-9]?|Exit Code: 0x00|Port's Linkspeed: 6|Port status: Active|Port-[0-9] :$|PI: No PI|Drive is formatted for PI information: No|PI Eligibility: No|Drive Temperature :|Drive: Not Certified|Media Type: Hard Disk Device|Link Speed: 6|Device Speed: 6|Needs EKM Attention: No|Locked: Unlocked|Secured: Unsecured|FDE Enable: Disable|FDE Capable: Not Capable|Connected Port Number: [0-9][0-9]?\(path[0-9][0-9]?\)|SAS Address\(1\): 0x0$|SAS Address\(0\):|Successful diagnostics completion on : N/A|Shield Counter: 0|Device Firmware Level: A001|Emergency Spare : No|Commissioned Spare : No|Physical Sector Size: 512|Logical Sector Size: 512|Sector Size: 512|Coerced Size:|Non Coerced Size:|Last Predictive Failure Event Seq Number: 0|Predictive Failure Count: 0|Other Error Count: 0|Media Error Count: 0|Sequence Number: [0-9][0-9]?|WWN:|Device Id:|Enclosure position:|Slot Number:|Enclosure Device ID:|Commissioned Spare : Yes|Firmware state: Hotspare, Spun down|Array #: 0, 1|Hotspare Information:|Type: Dedicated, is revertible|^$| " # Info to return about the drive RETURN_INFO="^PD|^Raw|^Firmware state|^Is Emergency|Inquiry Data|Foreign State|DiskGroup|Span|Physical Disk|Copyback" # Get a list of Adapters ADAPTERS=$(MegaCli -PDlist -aAll | grep Adapter | awk '{ print substr( $0, length($0), length($0) ) }') # Cycle through Adapters and get the EnclosureID's, and the Slots # There is so much fail right here, but so much less than MegaCli for ADAPTER in $ADAPTERS; do # Get a list of Enclosures ENCLOSURES=$(MegaCli -EncInfo -a$ADAPTER | grep "Device ID" | awk ' { print $4 } ') MISSING_DRIVES=$(MegaCli -Pdgetmissing -a$ADAPTER) for ENCLOSURE in $ENCLOSURES do # Get a list of slots... heh... slots sounds like sluts.... SLOTS=$(MegaCli -PDlist -a0 | grep -A1 "Device ID: $ENCLOSURE" | grep "Slot Number" | awk ' { print $3 } ') for SLOT in $SLOTS do # Check rebuild progress REBUILD_PROGRESS_ALL=$(MegaCli -pdrbld -showprog -physdrv[$ENCLOSURE:$SLOT] -a$ADAPTER | grep -vE "Exit Code: 0x00|not in rebuild|^$" | grep .) echo "$REBUILD_PROGRESS_ALL" | sed '/ /d' # Now check each drive, and grep against our Error list DRIVE=$(MegaCli -pdinfo -physdrv[$ENCLOSURE:$SLOT] -a$ADAPTER) BAD_DRIVE=$(echo "$DRIVE" | grep -vE "$NON_ERROR_FILTER") if [[ $BAD_DRIVE != "" ]]; then # Why have everything in one large-dump command, when you can split it into two large dump-commands with different specification options? MOAR_BAD_DRIVE_INFO=$(MegaCli -CfgDsply -a$ADAPTER | grep -B1 -A43 "Enclosure Device ID: $ENCLOSURE" | grep -B2 -A42 -E "Slot Number: $SLOT$" | grep -E "$RETURN_INFO" | grep -vE "$NON_ERROR_FILTER" | grep -vE "Exit Code: 0x00|^$") REBUILD_PROGRESS=$(MegaCli -pdrbld -showprog -physdrv[$ENCLOSURE:$SLOT] -a$ADAPTER | grep -vE "Exit Code: 0x00|^$|$NON_ERROR_FILTER") # Check copyback progress COPYBACK_PROGRESS=$(MegaCli -pdcpybk -showprog -physdrv[$ENCLOSURE:$SLOT] -a$ADAPTER | grep -vE "Exit Code: 0x00|not in Copyback|^$|$NON_ERROR_FILTER" | grep .) echo -e "Adapter: $ADAPTER, Enclosure: $ENCLOSURE, Slot: $SLOT\n$BAD_DRIVE\n$MOAR_BAD_DRIVE_INFO\n$REBUILD_PROGRESS\n$COPYBACK_PROGRESS\n" | grep -vE "^$" echo "" fi done done # This might not work. Needs to actually be tested on a system with a missing drive if [[ "$MISSING_DRIVES" == *"Expected"* ]]; then echo "\n$MISSING_DRIVES\n" fi done