-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsdevpy
209 lines (203 loc) · 5.36 KB
/
lsdevpy
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
#!/bin/bash
# ---------------------------------------------------------------------------
# lsdev - List devices in the system by their alias
# Copyright 2016, Brett Kelly <bkelly@45drives.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.############
############
declare -A BAY
declare -A BAYSTATUS
RED='\033[0;31m'
GREEN='\033[0;32m'
LGREEN='\033[1;32m'
LGREY='\033[1;37m'
DGREY='\033[1;30m'
YELLOW='\033[0;33m'
BLUE='\033[0;36m'
NC='\033[0m'
R750="0750"
LSI_9201="2116"
LSI_9305="3224"
ASR="Adaptec"
HBA1000="Adaptec Series 8"
R3740="3740"
line() { # takes a number as first input Length, and any character as second input, defaults to "-" if no option
if [ -z $2 ]; then
printf -v line '%*s' "$1"
echo ${line// /-}
else
printf -v line '%*s' "$1"
echo ${line// /$2}
fi
}
setBAYstatus() {
if [ ! -b /dev/disk/by-vdev/$DRIVE ];then
printf -v absent "$DGREY%-5s$NC" ${BAY[$1]}
BAYSTATUS[$1]=$absent
fi
partcount=$((ls /dev/disk/by-vdev/ | grep -w ${BAY[$1]} | wc -l) 2>/dev/null)
if [ "$partcount" -eq "1" ];then
printf -v present "$YELLOW%-5s$NC" ${BAY[$1]}
BAYSTATUS[$1]=$present
elif [ "$partcount" -gt "1" ];then
printf -v partition "$GREEN%-5s$NC" ${BAY[$1]}
BAYSTATUS[$1]=$partition
fi
}
setBAYstatusNC() {
if [ ! -b /dev/disk/by-vdev/$DRIVE ];then
printf -v absent "%-5s" ${BAY[$1]}
BAYSTATUS[$1]=$absent
fi
partcount=$((ls /dev/disk/by-vdev/ | grep -w ${BAY[$1]} | wc -l) 2>/dev/null)
if [ "$partcount" -eq "1" ];then
printf -v present "*%-5s" ${BAY[$1]}
BAYSTATUS[$1]=$present
elif [ "$partcount" -gt "1" ];then
printf -v partition "**%-5s" ${BAY[$1]}
BAYSTATUS[$1]=$partition
fi
}
getCARDname() {
if [[ $(lspci | grep $R750) ]];then
CARD="HighPoint R750"
DRIVERVERSION=$(cat /proc/scsi/r750/10 2>/dev/null | awk 'NR==1{print $5}')
elif [[ $(lspci | grep $LSI_9201) ]];then
CARD="LSI 9201-16i"
DRIVERVERSION=$(modinfo mpt2sas | grep version | awk 'NR==1{print $2}')
elif [[ $(lspci | grep $LSI_9305) ]];then
CARD="LSI 9305-16i"
DRIVERVERSION=$(modinfo mpt3sas | grep version | awk 'NR==1{print $2}')
elif [[ $(lspci | grep $HBA1000) ]];then
CARD="Adaptec HBA-1000i"
DRIVERVERSION=$(rpm -qa | grep -i aacraid)
fi
}
getBAY() {
i=0
j=3
## LOOP THROUGH BAYS
while [ $i -lt $BAYS ];do
bay=$(cat /etc/zfs/vdev_id.conf | awk -v j=$j 'NR==j{print $2}')
BAY[$i]=$bay
let i=i+1
let j=j+1
done
}
COLOR_FLAG=yes
while getopts 'nh' OPTION; do
case ${OPTION} in
n)
COLOR_FLAG=no
;;
esac
done
BAYS=$((cat /etc/zfs/vdev_id.conf| awk "NR>2" | wc -l) 2>/dev/null)
getCARDname
getBAY
printf "| %s %s %s %s |\n" Disk Controller: $CARD DriverVersion: $DRIVERVERSION
# initialize 4 counters, one for each potenital row in the server
WIDTH=15
WIDTH_=$(expr $WIDTH - 1)
i=0 # first row, start at 0
j=$(expr $i + $WIDTH) #2nd row offset i by width of the server
k=$(expr $i + $WIDTH + $WIDTH) # 3rd row offset i by 2 widths
l=$(expr $i + $WIDTH + $WIDTH + $WIDTH) # 4th row, offset by 3 widths
case $BAYS in
15)
#30unit
line 24 _
while [ $i -lt $WIDTH ];do
i_=$(expr $WIDTH_ - $i ) # invert counter for first row
if [ $COLOR_FLAG == no ];then
setBAYstatusNC $i_
else
setBAYstatus $i_
fi
printf "%s\n" "${BAYSTATUS[$i_]}" #displays drives in a snake pattern
let i=i+1
let j=j+1
done
line 24 -
printf "| %-5s |\n" ROW1
line 24 =
;;
30)
#30unit
line 24 _
while [ $i -lt $WIDTH ];do
i_=$(expr $WIDTH_ - $i ) # invert counter for first row
if [ $COLOR_FLAG == no ];then
setBAYstatusNC $i_
setBAYstatusNC $j
else
setBAYstatus $i_
setBAYstatus $j
fi
printf "%s|%s\n" "${BAYSTATUS[$i_]}" "${BAYSTATUS[$j]}" #displays drives in a snake pattern
let i=i+1
let j=j+1
done
line 24 -
printf "| %-5s | %-5s |\n" ROW1 ROW2
line 24 =
;;
45)
#45Unit
line 24 _
while [ $i -lt $WIDTH ];do
k_=$(expr $WIDTH + $WIDTH + $WIDTH_ - $i ) #invert counter for 3rd row
i_=$(expr $WIDTH_ - $i ) # invert counter for first row
if [ $COLOR_FLAG == no ];then
setBAYstatusNC $i_
setBAYstatusNC $j
setBAYstatusNC $k_
else
setBAYstatus $i_
setBAYstatus $j
setBAYstatus $k_
fi
printf "| %s | %s | %s |\n" "${BAYSTATUS[$i_]}" "${BAYSTATUS[$j]}" "${BAYSTATUS[$k_]}"
#printf "| %-7s | %-7s | %-7s |\n" ${BAY[$i]} ${BAY[$j]} ${BAY[$k]}
let i=i+1
let j=j+1
let k=k+1
done
line 24 -
printf "| %-5s | %-5s | %-5s |\n" ROW1 ROW2 ROW3
line 24 =
;;
60)
#60unit
line 32 _
while [ $i -lt $WIDTH ];do
k_=$(expr $WIDTH + $WIDTH + $WIDTH_ - $i )
i_=$(expr $WIDTH_ - $i )
if [ $COLOR_FLAG == no ];then
setBAYstatusNC $i_
setBAYstatusNC $j
setBAYstatusNC $k_
setBAYstatusNC $l
else
setBAYstatus $i_
setBAYstatus $j
setBAYstatus $k_
setBAYstatus $l
fi
printf "| %s | %s | %s | %s |\n" "${BAYSTATUS[$i_]}" "${BAYSTATUS[$j]}" "${BAYSTATUS[$k_]}" "${BAYSTATUS[$l]}"
let i=i+1
let j=j+1
let k=k+1
let l=l+1
done
line 32 -
printf "| %-5s | %-5s | %-5s | %-5s |\n" ROW1 ROW2 ROW3 ROW4
line 32 =
echo
;;
*)
echo -e "\nError!\n\tUnable to Display Drive Map\n\tConfigure Drive Aliasing (1)\n"
;;
esac