From b20d35102344d882f3faa6a85396dfa0dea074df Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:10:08 +1100 Subject: [PATCH] Create drive_info.sh --- drive_info.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 drive_info.sh diff --git a/drive_info.sh b/drive_info.sh new file mode 100644 index 0000000..a105d28 --- /dev/null +++ b/drive_info.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +for d in $(cat /proc/partitions | awk '{print $4}'); do + if [ ! -e /dev/"$d" ]; then + continue; + fi + #echo $d # debug + case "$d" in + sd*) + if [[ $d =~ [hs]d[a-z]$ ]]; then + echo -e "\n$d" # debug + hdmodel=$(smartctl -i "/dev/$d" | grep -i "Device Model:" | awk '{print $3 $4 $5}') + if [[ ! $hdmodel ]]; then + hdmodel=$(smartctl -i "/dev/$d" | grep -i "Product:" | awk '{print $2 $3 $4}') + fi + echo "Model: '$hdmodel'" # debug + + fwrev=$(smartctl -i "/dev/$d" | grep -i "Firmware Version:" | awk '{print $3}') + if [[ ! $fwrev ]]; then + fwrev=$(smartctl -i "/dev/$d" | grep -i "Revision:" | awk '{print $2}') + fi + echo "Firmware: '$fwrev'" # debug + fi + ;; + nvme*) + if [[ $d =~ nvme[0-9][0-9]?n[0-9][0-9]?$ ]]; then + echo -e "\n$d" # debug + n=n$(printf "%s" "$d" | cut -d "n" -f 2) + nvmemodel=$(cat "/sys/class/nvme/$n/model") + echo "NVMe Model: '$nvmemodel'" # debug + + nvmemodel=$(echo "$nvmemodel" | xargs) # trim leading and trailing white space + echo "NVMe Model: '$nvmemodel'" # debug + + nvmefw=$(cat "/sys/class/nvme/$n/firmware_rev") + echo "NVMe Firmware: '$nvmefw'" # debug + + nvmefw=$(echo "$nvmefw" | xargs) # trim leading and trailing white space + echo "NVMe Firmware: '$nvmefw'" # debug + + fi + ;; + esac +done + + +exit +