Add serial numbers to drive details output
Changes: - Added SERIAL column to SATA/SAS drive details table - Added SERIAL column to NVMe drive details table - Updated get_drive_smart_info() to extract and return serial numbers - Widened output format to accommodate serial numbers - NVMe serials now display correctly from nvme list output This makes it much easier to match drives to their physical locations by comparing visible serial numbers on drive labels with the output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -175,8 +175,9 @@ get_drive_smart_info() {
|
|||||||
local type=$(echo "$smart_info" | grep "Rotation Rate" | grep -q "Solid State" && echo "SSD" || echo "HDD")
|
local type=$(echo "$smart_info" | grep "Rotation Rate" | grep -q "Solid State" && echo "SSD" || echo "HDD")
|
||||||
local health=$(echo "$smart_info" | grep "SMART overall-health" | grep -q "PASSED" && echo "✓" || echo "✗")
|
local health=$(echo "$smart_info" | grep "SMART overall-health" | grep -q "PASSED" && echo "✓" || echo "✗")
|
||||||
local model=$(echo "$smart_info" | grep "Device Model\|Model Number" | cut -d: -f2 | xargs)
|
local model=$(echo "$smart_info" | grep "Device Model\|Model Number" | cut -d: -f2 | xargs)
|
||||||
|
local serial=$(echo "$smart_info" | grep "Serial Number" | awk '{print $3}')
|
||||||
|
|
||||||
echo "$type|$temp°C|$health|$model"
|
echo "$type|$temp°C|$health|$model|$serial"
|
||||||
}
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@@ -211,16 +212,16 @@ esac
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
echo -e "\n=== Drive Details with SMART Status ==="
|
echo -e "\n=== Drive Details with SMART Status ==="
|
||||||
printf "%-15s %-10s %-8s %-8s %-8s %-30s\n" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL"
|
printf "%-15s %-10s %-8s %-8s %-8s %-30s %-20s\n" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL"
|
||||||
echo "--------------------------------------------------------------------------------"
|
echo "----------------------------------------------------------------------------------------------------------------------------"
|
||||||
|
|
||||||
# SATA/SAS drives
|
# SATA/SAS drives
|
||||||
lsblk -d -o NAME | grep -v "nvme" | grep -v "rbd" | grep -v "loop" | grep -v "NAME" | while read device; do
|
lsblk -d -o NAME | grep -v "nvme" | grep -v "rbd" | grep -v "loop" | grep -v "NAME" | while read device; do
|
||||||
if [ -b "/dev/$device" ]; then
|
if [ -b "/dev/$device" ]; then
|
||||||
size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)
|
size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)
|
||||||
smart_info=$(get_drive_smart_info "$device")
|
smart_info=$(get_drive_smart_info "$device")
|
||||||
IFS='|' read -r type temp health model <<< "$smart_info"
|
IFS='|' read -r type temp health model serial <<< "$smart_info"
|
||||||
printf "%-15s %-10s %-8s %-8s %-8s %-30s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model"
|
printf "%-15s %-10s %-8s %-8s %-8s %-30s %-20s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model" "$serial"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -229,9 +230,9 @@ if command -v nvme >/dev/null 2>&1; then
|
|||||||
nvme_drives=$(sudo nvme list 2>/dev/null | grep "^/dev")
|
nvme_drives=$(sudo nvme list 2>/dev/null | grep "^/dev")
|
||||||
if [ -n "$nvme_drives" ]; then
|
if [ -n "$nvme_drives" ]; then
|
||||||
echo -e "\n=== NVMe Drives ==="
|
echo -e "\n=== NVMe Drives ==="
|
||||||
printf "%-15s %-10s %-10s %-40s\n" "DEVICE" "SIZE" "TYPE" "MODEL"
|
printf "%-15s %-10s %-10s %-40s %-20s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL"
|
||||||
echo "--------------------------------------------------------------------------------"
|
echo "----------------------------------------------------------------------------------------------------------------------------"
|
||||||
echo "$nvme_drives" | awk '{printf "%-15s %-10s %-10s %-40s\n", $1, $6, "NVMe", $3}'
|
echo "$nvme_drives" | awk '{printf "%-15s %-10s %-10s %-40s %-20s\n", $1, $6, "NVMe", $3, $2}'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user