-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetRaidDiskInfo.sh
More file actions
820 lines (726 loc) · 33.8 KB
/
Copy pathGetRaidDiskInfo.sh
File metadata and controls
820 lines (726 loc) · 33.8 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#!/bin/bash
declare -r megacli_tool="/opt/MegaRAID/MegaCli/MegaCli64"
declare -r ssacli_tool="/usr/sbin/ssacli"
Global_Status_RLevel=0
ipaddr="unknown"
SASDiskCount=0
declare -a SASDiskSize
declare -a SASDeviceSpeed
declare -a SASRaidLevelList
SATADiskCount=0
declare -a SATADiskSize
declare -a SATADeviceSpeed
declare -a SATARaidLevelList
SSDCount=0
declare -a SSDSize
declare -a SSDDeviceSpeed
declare -a SSDRaidLevelList
PCIECount=0
declare -a PCIESize
function GetIPAddr(){
if [ $(ip addr show |grep '10\.191\.' |wc -l) -ne 0 ]; then
ipaddr="$(ip -o -4 addr show scope global primary |grep '10\.191\.' |awk '{print $4}' |sed "s/\/.*//" |sed -n 1p)"
else
ipaddr="$(ip -o -4 addr show scope global primary |awk '{print $4}' |sed "s/\/.*//" |sed -n 1p)"
fi
}
function SAS_GetHDDCount(){
local l_pcount="$1"
SASDiskCount="$(( SASDiskCount + l_pcount ))"
unset l_pcount
}
function SAS_GetHDDSize(){
local l_psize="$1"
local l_psize_tag=0
for ((p=0;p<${#SASDiskSize[*]};p++));do
if [ x"${SASDiskSize[${p}]}" != x"" ]; then
if [ x"${SASDiskSize[${p}]}" == x"${l_psize}" ]; then
l_psize_tag=1
break
else
l_psize_tag=0
continue
fi
fi
done
if [ ${l_psize_tag} -eq 0 ]; then
SASDiskSize[${#SASDiskSize[*]}]="${l_psize}"
fi
unset p l_psize l_psize_tag
}
function SAS_GetHDDSpeed(){
local l_pspeed="$1"
local l_pspeed_tag=0
for ((s=0;s<${#SASDeviceSpeed[*]};s++));do
if [ x"${SASDeviceSpeed[${s}]}" != x"" ]; then
if [ x"${SASDeviceSpeed[${s}]}" == x"${l_pspeed}" ]; then
l_pspeed_tag=1
break
else
l_pspeed_tag=0
continue
fi
fi
done
if [ ${l_pspeed_tag} -eq 0 ]; then
SASDeviceSpeed[${#SASDeviceSpeed[*]}]="${l_pspeed}"
fi
unset s l_pspeed l_pspeed_tag
}
function SAS_MegaCli_GetHDDRaidList(){
local l_vdlevel="$1"
local l_spandepth="$2"
local l_vpdevnum="$3"
case "${l_vdlevel}" in
"Primary-0, Secondary-0, RAID Level Qualifier-0")
l_vdlevel=RAID0
;;
"Primary-1, Secondary-0, RAID Level Qualifier-0")
[ "${l_spandepth}" -eq 1 ] && l_vdlevel=RAID1
[ "${l_spandepth}" -gt 1 ] && l_vdlevel=RAID10
;;
"Primary-5, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID5
;;
"Primary-6, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID6
;;
"Primary-1, Secondary-3, RAID Level Qualifier-0")
l_vdlevel=RAID10
;;
*)
l_vdlevel=Unknown
;;
esac
local l_vpdevcount=$(( ${l_vpdevnum:-0} * ${l_spandepth:-0} ))
SASRaidLevelList[${#SASRaidLevelList[*]}]="${l_vdlevel}(${l_vpdevcount} pcs)"
unset l_vdlevel l_spandepth l_vpdevnum l_vpdevcount
}
function SATA_GetHDDCount(){
local l_pcount="$1"
SATADiskCount="$(( SATADiskCount + l_pcount ))"
unset l_pcount
}
function SATA_GetHDDSize(){
local l_psize="$1"
local l_psize_tag=0
for ((p=0;p<${#SATADiskSize[*]};p++));do
if [ x"${SATADiskSize[${p}]}" != x"" ]; then
if [ x"${SATADiskSize[${p}]}" == x"${l_psize}" ]; then
l_psize_tag=1
break
else
l_psize_tag=0
continue
fi
fi
done
if [ ${l_psize_tag} -eq 0 ]; then
SATADiskSize[${#SATADiskSize[*]}]="${l_psize}"
fi
unset p l_psize l_psize_tag
}
function SATA_GetHDDSpeed(){
local l_pspeed="$1"
local l_pspeed_tag=0
for ((s=0;s<${#SATADeviceSpeed[*]};s++));do
if [ x"${SATADeviceSpeed[${s}]}" != x"" ]; then
if [ x"${SATADeviceSpeed[${s}]}" == x"${l_pspeed}" ]; then
l_pspeed_tag=1
break
else
l_pspeed_tag=0
continue
fi
fi
done
if [ ${l_pspeed_tag} -eq 0 ]; then
SATADeviceSpeed[${#SATADeviceSpeed[*]}]="${l_pspeed}"
fi
unset s l_pspeed l_pspeed_tag
}
function SATA_MegaCli_GetHDDRaidList(){
local l_vdlevel="$1"
local l_spandepth="$2"
local l_vpdevnum="$3"
case "${l_vdlevel}" in
"Primary-0, Secondary-0, RAID Level Qualifier-0")
l_vdlevel=RAID0
;;
"Primary-1, Secondary-0, RAID Level Qualifier-0")
[ "${l_spandepth}" -eq 1 ] && l_vdlevel=RAID1
[ "${l_spandepth}" -gt 1 ] && l_vdlevel=RAID10
;;
"Primary-5, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID5
;;
"Primary-6, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID6
;;
"Primary-1, Secondary-3, RAID Level Qualifier-0")
l_vdlevel=RAID10
;;
*)
l_vdlevel=Unknown
;;
esac
local l_vpdevcount=$(( ${l_vpdevnum:-0} * ${l_spandepth:-0} ))
SATARaidLevelList[${#SATARaidLevelList[*]}]="${l_vdlevel}(${l_vpdevcount} pcs)"
unset l_vdlevel l_spandepth l_vpdevnum l_vpdevcount
}
function SSD_GetSSDCount(){
local l_pcount="$1"
SSDCount="$(( SSDCount + l_pcount ))"
unset l_pcount
}
function SSD_GetSSDSize(){
local l_psize="$1"
local l_psize_tag=0
for ((p=0;p<${#SSDSize[*]};p++));do
if [ x"${SSDSize[${p}]}" != x"" ]; then
if [ x"${SSDSize[${p}]}" == x"${l_psize}" ]; then
l_psize_tag=1
break
else
l_psize_tag=0
continue
fi
fi
done
if [ ${l_psize_tag} -eq 0 ]; then
SSDSize[${#SSDSize[*]}]="${l_psize}"
fi
unset p l_psize l_psize_tag
}
function SSD_GetSSDSpeed(){
local l_pspeed="$1"
local l_pspeed_tag=0
for ((s=0;s<${#SSDDeviceSpeed[*]};s++));do
if [ x"${SSDDeviceSpeed[${s}]}" != x"" ]; then
if [ x"${SSDDeviceSpeed[${s}]}" == x"${l_pspeed}" ]; then
l_pspeed_tag=1
break
else
l_pspeed_tag=0
continue
fi
fi
done
if [ ${l_pspeed_tag} -eq 0 ]; then
SSDDeviceSpeed[${#SSDDeviceSpeed[*]}]="${l_pspeed}"
fi
unset s l_pspeed l_pspeed_tag
}
function SSD_MegaCli_GetSSDRaidList(){
local l_vdlevel="$1"
local l_spandepth="$2"
local l_vpdevnum="$3"
case "${l_vdlevel}" in
"Primary-0, Secondary-0, RAID Level Qualifier-0")
l_vdlevel=RAID0
;;
"Primary-1, Secondary-0, RAID Level Qualifier-0")
[ "${l_spandepth}" -eq 1 ] && l_vdlevel=RAID1
[ "${l_spandepth}" -gt 1 ] && l_vdlevel=RAID10
;;
"Primary-5, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID5
;;
"Primary-6, Secondary-0, RAID Level Qualifier-3")
l_vdlevel=RAID6
;;
"Primary-1, Secondary-3, RAID Level Qualifier-0")
l_vdlevel=RAID10
;;
*)
l_vdlevel=Unknown
;;
esac
local l_vpdevcount=$(( ${l_vpdevnum:-0} * ${l_spandepth:-0} ))
SSDRaidLevelList[${#SSDRaidLevelList[*]}]="${l_vdlevel}(${l_vpdevcount} pcs)"
unset l_vdlevel l_spandepth l_vpdevnum l_vpdevcount
}
function PCIE_Nvme_GetSSDCount(){
local l_pcount="$1"
PCIECount="$(( PCIECount + l_pcount ))"
unset l_pcount
}
function PCIE_Nvme_GetSSDSize(){
local l_psize="$1"
local l_psize_tag=0
for ((p=0;p<${#PCIESize[*]};p++));do
if [ x"${PCIESize[${p}]}" != x"" ]; then
if [ x"${PCIESize[${p}]}" == x"${l_psize}" ]; then
l_psize_tag=1
break
else
l_psize_tag=0
continue
fi
fi
done
if [ ${l_psize_tag} -eq 0 ]; then
PCIESize[${#PCIESize[*]}]="${l_psize}"
fi
unset p l_psize l_psize_tag
}
function MegaCli_SAS_HDD(){
local l_vrstart="$1"
local l_vrend="$2"
local l_prstart="$3"
local l_prend="$4"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ] && [ x"{l_prstart}" != x"" ] && [ x"{l_prend}" != x"" ]; then
SAS_GetHDDCount "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<PD Type\>" |egrep "\<SAS\>" |wc -l)"
local l_psize="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SAS_GetHDDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SAS_GetHDDSpeed "${l_pspeed}"
fi
unset l_pspeed
if [ "${Global_Status_RLevel}" -eq 0 ]; then
local l_vdlevel="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "\<RAID Level\>" |sed -n 1p |sed "s/^RAID Level[[:space:]]*:[[:space:]]*//g")"
local l_spandepth="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Span Depth\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
local l_vpdevnum="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Number Of Drives\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
if [ x"${l_vdlevel}" != x"" ] && [ x"${l_spandepth}" != x"" ] && [ x"${l_vpdevnum}" != x"" ]; then
SAS_MegaCli_GetHDDRaidList "${l_vdlevel}" "${l_spandepth}" "${l_vpdevnum}"
fi
unset l_vdlevel l_spandepth l_vpdevnum
Global_Status_RLevel=1
fi
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend l_prstart l_prend
}
function MegaCli_SATA_HDD(){
local l_vrstart="$1"
local l_vrend="$2"
local l_prstart="$3"
local l_prend="$4"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ] && [ x"{l_prstart}" != x"" ] && [ x"{l_prend}" != x"" ]; then
SATA_GetHDDCount "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<PD Type\>" |egrep "\<SATA\>" |wc -l)"
local l_psize="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SATA_GetHDDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SATA_GetHDDSpeed "${l_pspeed}"
fi
unset l_pspeed
if [ "${Global_Status_RLevel}" -eq 0 ]; then
local l_vdlevel="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "\<RAID Level\>" |sed -n 1p |sed "s/^RAID Level[[:space:]]*:[[:space:]]*//g")"
local l_spandepth="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Span Depth\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
local l_vpdevnum="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Number Of Drives\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
if [ x"${l_vdlevel}" != x"" ] && [ x"${l_spandepth}" != x"" ] && [ x"${l_vpdevnum}" != x"" ]; then
SATA_MegaCli_GetHDDRaidList "${l_vdlevel}" "${l_spandepth}" "${l_vpdevnum}"
fi
unset l_vdlevel l_spandepth l_vpdevnum
Global_Status_RLevel=1
fi
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend l_prstart l_prend
}
function MegaCli_SAS_SSD(){
local l_vrstart="$1"
local l_vrend="$2"
local l_prstart="$3"
local l_prend="$4"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ] && [ x"{l_prstart}" != x"" ] && [ x"{l_prend}" != x"" ]; then
SSD_GetSSDCount "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Media Type\>" |egrep "\<Solid State Device\>" |wc -l)"
local l_psize="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SSD_GetSSDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SSD_GetSSDSpeed "${l_pspeed}"
fi
unset l_pspeed
if [ "${Global_Status_RLevel}" -eq 0 ]; then
local l_vdlevel="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "\<RAID Level\>" |sed -n 1p |sed "s/^RAID Level[[:space:]]*:[[:space:]]*//g")"
local l_spandepth="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Span Depth\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
local l_vpdevnum="$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |egrep "^\<Number Of Drives\>" |sed -n 1p |egrep -o "[[:digit:]]+")"
if [ x"${l_vdlevel}" != x"" ] && [ x"${l_spandepth}" != x"" ] && [ x"${l_vpdevnum}" != x"" ]; then
SSD_MegaCli_GetSSDRaidList "${l_vdlevel}" "${l_spandepth}" "${l_vpdevnum}"
fi
unset l_vdlevel l_spandepth l_vpdevnum
Global_Status_RLevel=1
fi
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend l_prstart l_prend
}
function MegaCli_SATA_SSD(){
local l_vrstart="$1"
local l_vrend="$2"
local l_prstart="$3"
local l_prend="$4"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ] && [ x"{l_prstart}" != x"" ] && [ x"{l_prend}" != x"" ]; then
MegaCli_SAS_SSD "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend l_prstart l_prend
}
function MegaCli_PDSwitch(){
local l_vrstart="$1"
local l_vrend="$2"
local l_prstart="$3"
local l_prend="$4"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ] && [ x"{l_prstart}" != x"" ] && [ x"{l_prend}" != x"" ]; then
case "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<PD Type\>" |sed -e "s/^PD Type:[[:space:]]*//g" |sort |uniq)" in
SAS)
case "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Media Type\>" |sed -e "s/^Media Type:[[:space:]]*//g" |sort |uniq)" in
"Hard Disk Device")
MegaCli_SAS_HDD "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
;;
"Solid State Device")
MegaCli_SAS_SSD "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
;;
*)
echo "Unknown media type"
;;
esac
;;
SATA)
case "$(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n "${l_prstart},${l_prend}p" |egrep "^\<Media Type\>" |sed -e "s/^Media Type:[[:space:]]*//g" |sort |uniq)" in
"Hard Disk Device")
MegaCli_SATA_HDD "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
;;
"Solid State Device")
MegaCli_SATA_SSD "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
;;
*)
echo "Unknown media type"
;;
esac
;;
*)
echo "Unknown PD type"
;;
esac
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend l_prstart l_prend
}
function MegaCli_VDSwitch(){
local l_vrstart="$1"
local l_vrend="$2"
if [ x"{l_vrstart}" != x"" ] && [ x"{l_vrend}" != x"" ]; then
declare -a l_pdlines
for plinenum in $(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n "${l_vrstart},${l_vrend}p" |sed -n '/^PD:[[:space:]]\+[[:digit:]]\+/=');do
l_pdlines[${#l_pdlines[*]}]="${plinenum}"
done
for ((x=0;x<${#l_pdlines[*]};x++));do
local l_prstart="${l_pdlines[${x}]}"
local l_prend="${l_pdlines[$(( ${x} + 1 ))]}"
if [ "${x}" -lt "$(( ${#l_pdlines[*]} - 1 ))" ]; then
MegaCli_PDSwitch "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
elif [ "${x}" -eq "$(( ${#l_pdlines[*]} - 1 ))" ]; then
[ x"${l_prend}" == x"" ] && l_prend='$'
MegaCli_PDSwitch "${l_vrstart}" "${l_vrend}" "${l_prstart}" "${l_prend}"
fi
done
unset x plinenum l_pdlines l_prstart l_prend
else
echo "Parameter non-compliance"
fi
unset l_vrstart l_vrend
}
function MegaCli_PDJBOD(){
for esid in $(${megacli_tool} -PDList -aALL -Nolog |egrep -i "^\<(Enclosure Device ID|Slot Number)\>[[:space:]]*:" |sed -e "N;s/\nSlot Number[[:space:]]*:[[:space:]]*\(.*\)/:\1/g" -e "s/Enclosure Device ID[[:space:]]*:[[:space:]]*//g");do
if [ x"$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep -i "^\<Firmware state\>[[:space:]]*:" |sed "s/^\<Firmware state\>[[:space:]]*:[[:space:]]*//g")" == x"JBOD" ]; then
case "$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<PD Type\>" |sed -e "s/^PD Type:[[:space:]]*//g")" in
SAS)
case "$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Media Type\>" |sed -e "s/^Media Type:[[:space:]]*//g")" in
"Hard Disk Device")
SAS_GetHDDCount "1"
local l_psize="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SAS_GetHDDSize "${l_psize}"
fi
local l_pspeed="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SAS_GetHDDSpeed "${l_pspeed}"
fi
unset l_psize l_pspeed
;;
"Solid State Device")
SSD_GetSSDCount "1"
local l_psize="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SSD_GetSSDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SSD_GetSSDSpeed "${l_pspeed}"
fi
unset l_pspeed
;;
*)
echo "Unknown media type"
;;
esac
;;
SATA)
case "$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Media Type\>" |sed -e "s/^Media Type:[[:space:]]*//g")" in
"Hard Disk Device")
SATA_GetHDDCount "1"
local l_psize="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SATA_GetHDDSize "${l_psize}"
fi
local l_pspeed="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SATA_GetHDDSpeed "${l_pspeed}"
fi
unset l_psize l_pspeed
;;
"Solid State Device")
SSD_GetSSDCount "1"
local l_psize="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Raw Size\>" |sed -e "s/^Raw Size:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SSD_GetSSDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${megacli_tool} -PDInfo -PhysDrv[${esid}] -aALL -Nolog |egrep "^\<Device Speed\>" |sed -e "s/^Device Speed:[[:space:]]*//g" -e "s/[[:space:]]*\[.*$//g" -e 's/ //g')"
if [ x"${l_pspeed}" != x"" ]; then
SSD_GetSSDSpeed "${l_pspeed}"
fi
unset l_pspeed
;;
*)
echo "Unknown media type"
;;
esac
;;
*)
echo "Unknown PD type"
;;
esac
fi
done
unset esid
}
function MegaCliGetInfo(){
if [ -f "${megacli_tool}" ]; then
declare -a l_vdlines
for vlinenum in $(${megacli_tool} -LdPdInfo -aALL -Nolog |sed -n '/^Virtual Drive:[[:space:]]*[[:digit:]]\+/=');do
l_vdlines[${#l_vdlines[*]}]="${vlinenum}"
done
for ((i=0;i<${#l_vdlines[*]};i++));do
local l_vrstart="${l_vdlines[${i}]}"
local l_vrend="${l_vdlines[$(( ${i} + 1 ))]}"
Global_Status_RLevel=0
if [ "${i}" -lt "$(( ${#l_vdlines[*]} - 1 ))" ]; then
MegaCli_VDSwitch "${l_vrstart}" "${l_vrend}"
elif [ "${i}" -eq "$(( ${#l_vdlines[*]} - 1 ))" ]; then
[ x"${l_vrend}" == x"" ] && l_vrend='$'
MegaCli_VDSwitch "${l_vrstart}" "${l_vrend}"
fi
done
unset i vlinenum l_vdlines l_vrstart l_vrend
if [ $(${megacli_tool} -PDList -aALL -Nolog |egrep -i "^\<Firmware state\>[[:space:]]*:" |egrep "JBOD" |wc -l) -gt 0 ]; then
MegaCli_PDJBOD
fi
else
echo "${megacli_tool} not found"
fi
}
function Ssacli_SAS_HDD(){
local l_slotid="$1"
local l_arrayid="$2"
if [ x"{l_slotid}" != x"" ] && [ x"{l_arrayid}" != x"" ]; then
SAS_GetHDDCount "$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
for l_pdid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |awk '{print $2}');do
if [ x"${l_pdid}" != x"" ]; then
local l_psize="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<Size\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<Size\>:[[:space:]]\+//g' -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SAS_GetHDDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<PHY Transfer Rate\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<PHY Transfer Rate\>:[[:space:]]\+//g' -e 's/,.*$//g')"
if [ x"${l_pspeed}" != x"" ]; then
SAS_GetHDDSpeed "${l_pspeed}"
fi
unset l_pspeed
fi
done
unset l_pdid
for l_ldid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld all show |egrep "\<logicaldrive\>[[:space:]]+[[:digit:]]+" |awk '{print $2}');do
if [ x"${l_ldid}" != x"" ]; then
local l_ldlevel="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld "${l_ldid}" show status |egrep "\<logicaldrive\>" |awk -F ' |,|)' '{print $9 $10}')"
local l_pdcount="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
SASRaidLevelList[${#SASRaidLevelList[*]}]="${l_ldlevel}(${l_pdcount} pcs)"
fi
done
unset l_ldid l_ldlevel l_pdcount
else
echo "Parameter non-compliance"
fi
unset l_slotid l_arrayid
}
function Ssacli_SATA_HDD(){
local l_slotid="$1"
local l_arrayid="$2"
if [ x"{l_slotid}" != x"" ] && [ x"{l_arrayid}" != x"" ]; then
SATA_GetHDDCount "$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
for l_pdid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |awk '{print $2}');do
if [ x"${l_pdid}" != x"" ]; then
local l_psize="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<Size\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<Size\>:[[:space:]]\+//g' -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SATA_GetHDDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<PHY Transfer Rate\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<PHY Transfer Rate\>:[[:space:]]\+//g' -e 's/,.*$//g')"
if [ x"${l_pspeed}" != x"" ]; then
SATA_GetHDDSpeed "${l_pspeed}"
fi
unset l_pspeed
fi
done
unset l_pdid
for l_ldid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld all show |egrep "\<logicaldrive\>[[:space:]]+[[:digit:]]+" |awk '{print $2}');do
if [ x"${l_ldid}" != x"" ]; then
local l_ldlevel="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld "${l_ldid}" show status |egrep "\<logicaldrive\>" |awk -F ' |,|)' '{print $9 $10}')"
local l_pdcount="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
SATARaidLevelList[${#SATARaidLevelList[*]}]="${l_ldlevel}(${l_pdcount} pcs)"
fi
done
unset l_ldid l_ldlevel l_pdcount
else
echo "Parameter non-compliance"
fi
unset l_slotid l_arrayid
}
function Ssacli_SATA_SSD(){
local l_slotid="$1"
local l_arrayid="$2"
if [ x"{l_slotid}" != x"" ] && [ x"{l_arrayid}" != x"" ]; then
SSD_GetSSDCount "$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
for l_pdid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |awk '{print $2}');do
if [ x"${l_pdid}" != x"" ]; then
local l_psize="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<Size\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<Size\>:[[:space:]]\+//g' -e 's/ //g')"
if [ x"${l_psize}" != x"" ]; then
SSD_GetSSDSize "${l_psize}"
fi
unset l_psize
local l_pspeed="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd "${l_pdid}" show |egrep "^[[:space:]]+\<PHY Transfer Rate\>:[[:space:]]+" |sed -e 's/^[[:space:]]\+\<PHY Transfer Rate\>:[[:space:]]\+//g' -e 's/,.*$//g')"
if [ x"${l_pspeed}" != x"" ]; then
SSD_GetSSDSpeed "${l_pspeed}"
fi
unset l_pspeed
fi
done
unset l_pdid
for l_ldid in $(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld all show |egrep "\<logicaldrive\>[[:space:]]+[[:digit:]]+" |awk '{print $2}');do
if [ x"${l_ldid}" != x"" ]; then
local l_ldlevel="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" ld "${l_ldid}" show status |egrep "\<logicaldrive\>" |awk -F ' |,|)' '{print $9 $10}')"
local l_pdcount="$(${ssacli_tool} ctrl slot="${l_slotid}" array "${l_arrayid}" pd all show |egrep "\<physicaldrive\>" |wc -l)"
SSDRaidLevelList[${#SSDRaidLevelList[*]}]="${l_ldlevel}(${l_pdcount} pcs)"
fi
done
unset l_ldid l_ldlevel l_pdcount
else
echo "Parameter non-compliance"
fi
unset l_slotid l_arrayid
}
function SsacliGetInfo(){
if [ -f "${ssacli_tool}" ]; then
for slotid in $(${ssacli_tool} ctrl all show |egrep -o "\<Slot\>[[:space:]]+[[:digit:]]+" |egrep -o "[[:digit:]]+");do
for arrayid in $(${ssacli_tool} ctrl slot=${slotid} array all show |egrep "^[[:space:]]+\<Array\>" |awk '{print $2}');do
case "$(${ssacli_tool} ctrl slot=${slotid} array ${arrayid} show |egrep "^[[:space:]]+\<Interface Type\>:[[:space:]]+" |sed 's/^[[:space:]]\+\<Interface Type\>:[[:space:]]\+//g')" in
SAS)
Ssacli_SAS_HDD "${slotid}" "${arrayid}"
;;
SATA)
Ssacli_SATA_HDD "${slotid}" "${arrayid}"
;;
"Solid State SATA")
Ssacli_SATA_SSD "${slotid}" "${arrayid}"
;;
*)
echo "Unknown array interface type"
;;
esac
done
unset arrayid
done
unset slotid
else
echo "${ssacli_tool} not found"
fi
}
function NvmeSSDGetInfo(){
local lsblk="$(which lsblk 2>/dev/null)"
if [ x"${lsblk}" != x"" ] && [ -x "${lsblk}" ]; then
PCIE_Nvme_GetSSDCount "$(${lsblk} |egrep "^nvme" |wc -l)"
if [ $(${lsblk} |egrep "^nvme" |wc -l) -gt 0 ]; then
for l_psize in $(${lsblk} |egrep "^nvme" |awk '{print $4}');do
if [ x"${l_psize}" != x"" ]; then
PCIE_Nvme_GetSSDSize "${l_psize}"
fi
done
unset l_psize
fi
else
echo "lsblk not found"
fi
}
function PrintAllInfo(){
printf "%-20s: %-16s\n" "Host IP" "${ipaddr}"
printf "%-20s: %-16s\n" "SAS Disk total" "${SASDiskCount:-0}"
printf "%-20s: %-16s\n" "SAS Disk Size" "${SASDiskSize[*]:-0}"
printf "%-20s: %-16s\n" "SAS Device Speed" "${SASDeviceSpeed[*]:-0}"
printf "%-20s: %-16s\n" "SAS RAID Level" "${SASRaidLevelList[*]:-0}"
printf "%-20s: %-16s\n" "SATA Disk total" "${SATADiskCount:-0}"
printf "%-20s: %-16s\n" "SATA Disk Size" "${SATADiskSize[*]:-0}"
printf "%-20s: %-16s\n" "SATA Device Speed" "${SATADeviceSpeed[*]:-0}"
printf "%-20s: %-16s\n" "SATA RAID Level" "${SATARaidLevelList[*]:-0}"
printf "%-20s: %-16s\n" "SSD Disk total" "${SSDCount:-0}"
printf "%-20s: %-16s\n" "SSD Disk Size" "${SSDSize[*]:-0}"
printf "%-20s: %-16s\n" "SSD Device Speed" "${SSDDeviceSpeed[*]:-0}"
printf "%-20s: %-16s\n" "SSD RAID Level" "${SSDRaidLevelList[*]:-0}"
printf "%-20s: %-16s\n" "PCIE Disk total" "${PCIECount:-0}"
printf "%-20s: %-16s\n" "PCIE Disk Size" "${PCIESize[*]:-0}"
}
function main(){
if [ -r /sys/class/dmi/id/board_vendor ]; then
manufacturer="$(cat /sys/class/dmi/id/board_vendor |awk '{print $1}')"
elif [ -r /sys/class/dmi/id/chassis_vendor ]; then
manufacturer="$(cat /sys/class/dmi/id/chassis_vendor |awk '{print $1}')"
elif [ -r /sys/class/dmi/id/bios_vendor ]; then
manufacturer="$(cat /sys/class/dmi/id/bios_vendor |awk '{print $1}')"
else
manufacturer=""
fi
if [ -n "${manufacturer}" ] && [ x"${manufacturer}" != x"" ]; then
GetIPAddr
case "${manufacturer}" in
HP|hp|H3C|h3c)
SsacliGetInfo
;;
*)
MegaCliGetInfo
;;
esac
NvmeSSDGetInfo
PrintAllInfo
else
echo "Unknown Vendor"
fi
}
main