summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve@einval.com>2023-10-29 17:13:56 +0000
committerSteve McIntyre <steve@einval.com>2023-10-29 17:18:05 +0000
commit9233ad741bce9e5d2e5d72e141e9e92f27ca8776 (patch)
tree60c33b08d0794f6e9934757f32ca5b943c16fa77
parentdcd473b2f14a373db89b026ea10e36012218d247 (diff)
downloadsteve-scripts-9233ad741bce9e5d2e5d72e141e9e92f27ca8776.zip
disk-details: Add support for NVME devices
-rwxr-xr-xdisk-details105
1 files changed, 85 insertions, 20 deletions
diff --git a/disk-details b/disk-details
index 00aa922..0c3d329 100755
--- a/disk-details
+++ b/disk-details
@@ -6,30 +6,95 @@ export PATH
if [ "$1"x != ""x ] ; then
DEVICES="$@"
else
- DEVICES="/dev/sd?"
+ DEVICES="/dev/sd? /dev/nvme?n1"
fi
-for DEVICE in ${DEVICES}; do
- echo -n "${DEVICE}: "
- sg_inq ${DEVICE} >/dev/null 2>&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} | awk '
+ /Vendor/ {
+ VENDOR=$3
+ }
+ /Product identification/ {
+ if (NF == 3) {
+ PRODUCT=$3
+ } else {
+ PRODUCT=sprintf("%s %s", $3, $4)
+ }
+ }
+ /Product revision level/ {
+ FW=$4
+ }
+ /Unit serial/ {
+ SERIAL=$4
+ printf("%-8.8s %-16.16s %-8.8s %-24s ", VENDOR, PRODUCT, FW, SERIAL)
+ }'
+ if [ $? -ne 0 ]; then
+ echo " [ERRORS]"
+ fi
+ sg_readcap ${DEVICE} | awk '/Device size:/ {print $7,$8}'
+ fi
+# smartctl -a $DEVICE | grep -e "Start_Stop_Count" -e "Load_Cycle_Count"
+}
+
+# Sigh, NVME devices show a different formate
+nvme_data () {
+ DEVICE=$1
+
+ sg_inq ${DEVICE} >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo " [ERRORS]"
+ else
+ sg_inq ${DEVICE} | awk '
+ /Model number:/ {
+ VENDOR_PROD=$0
+ gsub("^.*Model number: ","",VENDOR_PROD)
+ }
+ /Serial number:/ {
+ SERIAL=$0
+ gsub("^.*Serial number: ","",SERIAL)
+ }
+ /Firmware revision:/ {
+ FW=$0
+ gsub("^.*Firmware revision: ","",FW)
+ printf("%-25.25s %-8.8s %-24s ", VENDOR_PROD, FW, SERIAL)
+ }'
if [ $? -ne 0 ]; then
echo " [ERRORS]"
- else
- sg_inq ${DEVICE} | awk '
- /Vendor/ { VENDOR=$3 }
- /Product identification/ { if (NF == 3)
- {
- PRODUCT=$3
- } else {
- PRODUCT=sprintf("%s %s", $3, $4) }
- }
- /Product revision level/ { FW=$4 }
- /Unit serial/ { SERIAL=$4 ; printf("%-8.8s %-16.16s %-4.4s %-24s ", VENDOR, PRODUCT, FW, SERIAL)}
-'
- if [ $? -ne 0 ]; then
- echo " [ERRORS]"
- fi
- sg_readcap ${DEVICE} | awk '/Device size:/ {print $7,$8}'
fi
+ sg_readcap ${DEVICE} | awk '/Device size:/ {print $7,$8}'
+ fi
# smartctl -a $DEVICE | grep -e "Start_Stop_Count" -e "Load_Cycle_Count"
+}
+
+for DEVICE in ${DEVICES}; do
+
+ if [ ! -e "$DEVICE" ]; then
+ continue
+ fi
+
+ PD="${DEVICE}: "
+
+ printf "%-15.15s" ${PD}
+
+ case $DEVICE in
+ /dev/sd*)
+ sg_data $DEVICE;;
+ /dev/nvme*)
+ nvme_data $DEVICE;;
+ *)
+ echo "Unknown device type $DEVICE"
+ ;;
+ esac
+
done