blob: 03dbf3b3b012870d68b72720098af87f7a1e7527 (
plain)
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
|
#!/bin/sh
PATH=/usr/sbin:$PATH
export PATH
if [ "$1"x != ""x ] ; then
DEVICES="$@"
else
DEVICES="/dev/sd? /dev/nvme?n1"
fi
print_capacity () {
DEVICE=$1
sg_readcap ${DEVICE} | perl -e '
while (<STDIN>) {
chomp;
m/Device size:.*\s+(\S+\s+GB)/ and printf("%11.11s\n", $1);
}'
}
# Parse the output of sg_inq
sg_data () {
DEVICE=$1
if [ ! -e "$DEVICE" ]; then
return
fi
sg_inq ${DEVICE} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo " [ERRORS]"
else
sg_inq ${DEVICE} | perl -e '
while (<STDIN>) {
chomp;
m/Vendor identification:\s+(.*)/ and $vendor = $1;
m/Product identification:\s+(.*)/ and $product = $1;
m/Product revision level:\s+(.*)/ and $fw = $1;
m/Unit serial number:\s+(.*)/ and $serial = $1;
}
printf("%-8.8s %-16.16s %-8.8s %-24s ", $vendor, $product, $fw, $serial)'
if [ $? -ne 0 ]; then
echo " [ERRORS]"
fi
print_capacity ${DEVICE}
fi
# smartctl -a $DEVICE | grep -e "Start_Stop_Count" -e "Load_Cycle_Count"
}
# Sigh, NVME devices output a different format
nvme_data () {
DEVICE=$1
sg_inq ${DEVICE} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo " [ERRORS]"
else
sg_inq ${DEVICE} | perl -e '
while (<STDIN>) {
chomp;
m/Model number:\s+(.*)/ and $vendor_prod = $1;
m/Serial number:\s+(.*)/ and $serial = $1;
m/Firmware revision:\s+(.*)/ and $fw = $1;
m/Unit serial number:\s+(.*)/ and $serial = $1;
}
printf("%-25.25s %-8.8s %-24s ", $vendor_prod, $fw, $serial)'
if [ $? -ne 0 ]; then
echo " [ERRORS]"
fi
print_capacity ${DEVICE}
fi
# smartctl -a $DEVICE | grep -e "Start_Stop_Count" -e "Load_Cycle_Count"
}
for DEVICE in ${DEVICES}; do
if [ -e "$DEVICE" ]; then
printf "%-15.15s" "${DEVICE}:"
case $DEVICE in
/dev/sd*)
sg_data $DEVICE;;
/dev/nvme*)
nvme_data $DEVICE;;
*)
echo "Unknown device type $DEVICE"
;;
esac
fi
done
|