>>101064982
heres the script if anyone else wants it
it was just meant so I could plan which drives will be replaced next. I'd also want to make it show the average temperatures over the lat 48 hours but I'd need to have it poll smartctl for that like every hour for two days, unsure how that'd work
#!/bin/bash
drives=()
echo "Gathering SMART information..."
for drive in /dev/sd?; do
smart_status=$(smartctl -iA "$drive" 2>/dev/null)
if [[ $smart_status == *"SMART"* ]]; then
# Extract power-on hours and device model
if [[ $smart_status == *"Power_On_Hours"* ]]; then
power_on_hours=$(echo "$smart_status" | grep "Power_On_Hours" | awk '{print $10}')
else
power_on_hours=$(echo "$smart_status" | grep "Accumulated power on time")
power_on_hours="${power_on_hours##* }"
power_on_hours="${power_on_hours%%:*}"
# I don't know sed pls dont laugh
fi
power_on_yd="$(($power_on_hours / 8765)) Years, $(($power_on_hours % 8765 / 24)) Days, $(($power_on_hours % 24)) Hours"
if [[ $smart_status == *"Vendor:"* ]]; then
drive_vendor=$(echo "$smart_status" | grep 'Vendor:')
drive_product=$(echo "$smart_status" | grep 'Product:')
drive_model="${drive_vendor##* } ${drive_product##* }"
else
drive_model=$(echo "$smart_status" | grep 'Device Model:')
drive_model="${drive_model##* }"
fi
# Store drive information in the array
drives+=("$power_on_yd|$drive_model|$drive")
fi
done
IFS=$'\n' sorted_drives=($(sort -Vr <<<"${drives[*]}"))
unset IFS
echo
printf "%-10s | %-28s | %s\n" "Drive Path" "Power On Time" "Drive Model"
echo "-------------------------------------------------------"
for drive in "${sorted_drives[@]}"; do
IFS='|' read -ra drive_info <<<"$drive"
printf "%-10s | %-28s | %s\n" "${drive_info[2]}" "${drive_info[0]}" "${drive_info[1]}"
done