/
MegaRAID_SUM
executable file
·224 lines (198 loc) · 10.1 KB
/
MegaRAID_SUM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
#
# Script to check MegaRaidCLI status and Critical/Failed drives
#
# Example:
# ------------------------------------
# Extra options: ./MegaRAID_SUM --help
# ------------------------------------
#
# Device Present
# ================
# Virtual Drives : 16
# Degraded : 0
# Offline : 2
# Physical Devices : 19
# Disks : 17
# Critical Disks : 0
# Failed Disks : 2
#
#
# Virtual Drive: 0 | RAIDlvl: 1 | #Drives: 2 | State: Optimal | Span Ref: 00 | Size: 278.0 GB
# Virtual Drive: 1 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 01 | Size: 2.727 TB
# Virtual Drive: 2 | RAIDlvl: 0 | #Drives: 1 | State: Offline | Span Ref: 02 | Size: 2.727 TB
# Virtual Drive: 3 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 03 | Size: 2.727 TB
# Virtual Drive: 4 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 04 | Size: 2.727 TB
# Virtual Drive: 5 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 05 | Size: 2.727 TB
# Virtual Drive: 6 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 06 | Size: 2.727 TB
# Virtual Drive: 7 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 07 | Size: 2.727 TB
# Virtual Drive: 8 | RAIDlvl: 0 | #Drives: 1 | State: Offline | Span Ref: 08 | Size: 3.637 TB
# Virtual Drive: 9 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 09 | Size: 2.727 TB
# Virtual Drive: 10 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0a | Size: 2.727 TB
# Virtual Drive: 16 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0b | Size: 2.727 TB
# Virtual Drive: 11 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0c | Size: 3.637 TB
# Virtual Drive: 12 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0d | Size: 3.637 TB
# Virtual Drive: 14 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0e | Size: 3.637 TB
# Virtual Drive: 15 | RAIDlvl: 0 | #Drives: 1 | State: Optimal | Span Ref: 0f | Size: 2.727 TB
#
# Slot: 0 - Drive's position: DiskGroup: 1, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 1 - Drive's position: DiskGroup: 2, Span: 0, Arm: 0 - Failed
# Slot: 2 - Drive's position: DiskGroup: 3, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 3 - Drive's position: DiskGroup: 4, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 4 - Drive's position: DiskGroup: 5, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 5 - Drive's position: DiskGroup: 6, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 6 - Drive's position: DiskGroup: 7, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 7 - Drive's position: DiskGroup: 8, Span: 0, Arm: 0 - Failed
# Slot: 8 - Drive's position: DiskGroup: 9, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 9 - Drive's position: DiskGroup: 10, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 10 - Drive's position: DiskGroup: 12, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 11 - Drive's position: DiskGroup: 13, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 13 - Drive's position: DiskGroup: 14, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 14 - Drive's position: DiskGroup: 15, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 15 - Drive's position: DiskGroup: 11, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 0 - Drive's position: DiskGroup: 0, Span: 0, Arm: 0 - Online, Spun Up
# Slot: 1 - Drive's position: DiskGroup: 0, Span: 0, Arm: 1 - Online, Spun Up
#
replace_failed(){
faild=$(sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL | /bin/egrep "Failed" | wc -l)
if [ "$faild" -ge 1 ]; then
sudo /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aALL > Cfgdsply-text
mapfile -t failed_line < <( cat Cfgdsply-text | /bin/egrep -n "Failed" | cut -d':' -f1 )
for (( i = 0; i < ${#failed_line[@]}; i++)); do
sed -n "1,${failed_line[$i]}p" Cfgdsply-text > Cfgdsply-tofailed-text
tac Cfgdsply-tofailed-text > backw-Cfgdsplytext
fadpt=$(/bin/egrep -m 1 "Adapter" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
enclID=$(/bin/egrep -m 1 "Enclosure Device ID" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
slot=$(/bin/egrep -m 1 "Slot Number" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
spanref=$(/bin/egrep -m 1 "Span Reference" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g" | cut -d'x' -f2 | cut -c 2)
row=$(/bin/egrep -m 1 "Physical Disk:" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
echo "Replace Drive at: adapter: # $fadpt - enclID: $enclID - slot: $slot | Span ref: $spanref | Row: $row ??"
echo "(yes) or (no)"
read REPLACE
if [ "$REPLACE" == "yes" ]; then
echo "Setting disk offline..."
sudo /opt/MegaRAID/MegaCli/MegaCli64 -pdoffline -physdrv[$enclID:$slot] -a$fadpt
echo "Marking disk as missing..."
sudo /opt/MegaRAID/MegaCli/MegaCli64 -pdmarkmissing -physdrv[$enclID:$slot] -a$fadpt
echo "Preparing for removal..."
sudo /opt/MegaRAID/MegaCli/MegaCli64 -pdprprmv -physdrv[$enclID:$slot] -a$fadpt
echo
echo "Replace disk now..."
echo "Done? (yes) or (no)"
read DONE
if [ "$DONE" == “yes” ]; then
echo "Replace missing and start rebuilding..."
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PdReplaceMissing -PhysDrv[$enclID:$slot] -Array$spanref -row$row -a$fadpt
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -Start -PhysDrv [$enclID:$slot] -a$fadpt
else
exit
fi
else
continue
fi
done
# cleanup tmp files
rm -f Cfgdsply-text
rm -f Cfgdsply-tofailed-text
rm -f backw-Cfgdsplytext
else
echo "No Failed drives"
fi
}
show_failed(){
faild=$(sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL | /bin/egrep "Failed" | wc -l)
if [ "$faild" -ge 1 ]; then
sudo /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aALL > Cfgdsply-text
mapfile -t failed_line < <( cat Cfgdsply-text | /bin/egrep -n "Failed" | cut -d':' -f1 )
for (( i = 0; i < ${#failed_line[@]}; i++)); do
sed -n "1,${failed_line[$i]}p" Cfgdsply-text > Cfgdsply-tofailed-text
tac Cfgdsply-tofailed-text > backw-Cfgdsplytext
fadpt=$(/bin/egrep -m 1 "Adapter" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
enclID=$(/bin/egrep -m 1 "Enclosure Device ID" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
slot=$(/bin/egrep -m 1 "Slot Number" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
spanref=$(/bin/egrep -m 1 "Span Reference" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g" | cut -d'x' -f2 | cut -c 2)
row=$(/bin/egrep -m 1 "Physical Disk:" backw-Cfgdsplytext | cut -d':' -f2 | sed -e "s/ //g")
echo "Failed at:"
echo " adapter: # $fadpt - enclID: $enclID - slot: $slot | Span ref: $spanref | Row: $row"
echo
echo "Start blinking LED on drives?(start) or Stop blinking (stop)"
read STARTB
if [ "$STARTB" == "start" ]; then
echo "sudo /opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -start -physdrv \[$enclID:$slot\] -a$fadpt"
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -start -physdrv \[$enclID:$slot\] -a$fadpt
elif [ "$STARTB" == "stop" ]; then
echo "sudo /opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -stop -physdrv \[$enclID:$slot\] -a$fdapt"
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -stop -physdrv \[$enclID:$slot\] -a$fdapt
else
continue
fi
done
# cleanup tmp files
rm -f Cfgdsply-text
rm -f Cfgdsply-tofailed-text
rm -f backw-Cfgdsplytext
else
echo "No Failed drives"
fi
}
arg=$1
case $arg in
-h|--help)
echo "-h show options"
echo "-a show all MegaRAID info"
echo "-p show physical drives info "
echo "-v show virtual drive & physical info"
echo "-f show failed drive info"
echo "-r replace failed drive"
;;
-a)
sudo /opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll | less
;;
-p)
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL | less
;;
-v)
sudo /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aALL | less
;;
-f)
show_failed
;;
-r)
replace_failed
;;
esac
if [ $# -eq 0 ]; then
echo "------------------------------------"
echo "Extra options: ${0} --help"
echo "------------------------------------"
echo
sudo /opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll > Adpallinfo-text
sudo /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aALL > Cfgdsply-text
sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL > Pdlist-text
degrade=$(cat Adpallinfo-text | /bin/egrep 'Degrade' | awk '/[0-9]/ {print $3}')
offline=$(cat Adpallinfo-text | /bin/egrep '[[:space:]][[:space:]]Offline' | awk '/[0-9]/ {print $3}')
critical=$(cat Adpallinfo-text | /bin/egrep 'Critical' | awk '/[0-9]/ {print $4}')
failed=$(cat Adpallinfo-text | /bin/egrep '[[:space:]][[:space:]]Failed' | awk '/[0-9]/ {print $4}')
mapfile -t VIRTdrives < <(cat Cfgdsply-text | /bin/egrep 'Virtual Drive:'| cut -d'(' -f1)
mapfile -t RAIDlvl < <(cat Cfgdsply-text | /bin/egrep 'RAID Level' | awk ' {print $4}'| cut -d'-' -f2 | cut -c1)
mapfile -t drivenum < <(cat Cfgdsply-text | /bin/egrep 'Drives' | cut -d':' -f2)
mapfile -t RAIDstate < <(cat Cfgdsply-text | /bin/egrep 'State\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s' | cut -d':' -f2)
mapfile -t RAIDsize < <(cat Cfgdsply-text | /bin/egrep 'Size\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s:'| cut -d':' -f2)
mapfile -t SPANref < <(cat Cfgdsply-text | /bin/egrep 'Span Reference' | cut -d':' -f2 | cut -d'x' -f2)
cat Adpallinfo-text | /bin/egrep -A 9 'Device Present'
echo
for (( i = 0; i < ${#VIRTdrives[@]}; i++)); do
echo "${VIRTdrives[$i]} | RAIDlvl: ${RAIDlvl[$i]} | #Drives:${drivenum[$i]} | State:${RAIDstate[$i]} | Span Ref: ${SPANref[$i]} | Size:${RAIDsize[$i]}"
done
mapfile -t slotnum < <(cat Pdlist-text | /bin/grep 'Slot Number'| cut -d':' -f2 | cut -c2-3)
mapfile -t firmstate < <(cat Pdlist-text | /bin/grep "Firmware state" | cut -d':' -f2)
mapfile -t position < <(cat Pdlist-text | /bin/grep "Drive's position" | cut -f2,4)
echo
for (( i = 0; i < ${#slotnum[@]}; i++)); do
echo "Slot: ${slotnum[$i]} - ${position[$i]} - ${firmstate[$i]}"
done
# cleanup tmp files
rm -f Adpallinfo-text
rm -f Cfgdsply-text
rm -f Pdlist-text
fi