Hi all, just in case you were wondering how to quickly check the results of your last smartctl runs other than tediously navigating via Truenas Community Web UI, then here is a script generated by ChatGPT. Please let me know if you find it useful or complete non-sense and there is an easier way to scan all drives and see the results in a human readable format. This script in particular shows how long ago in hours the tests were run in the column “Difference”. Here is the zsh script “smart_test_summary.zsh”:
#!/bin/zsh
# Print header
printf "%-8s %-20s %-20s %-10s %-12s %-12s %-10s %-20s\n" \
"Disk" "Model" "Serial" "On_Hours" "Test_Hours" "Difference" "Type" "Result"
printf "%-8s %-20s %-20s %-10s %-12s %-12s %-10s %-20s\n" \
"--------" "--------------------" "--------------------" "--------" "------------" "------------" "----------" "--------------------"
# Get all disk devices
drives=($(lsblk -dno NAME,TYPE | awk '$2=="disk" {print "/dev/" $1}'))
for drive in $drives; do
# Skip if SMART not available
if ! sudo smartctl -i "$drive" >/dev/null 2>&1; then
continue
fi
# Get model and serial
model=$(sudo smartctl -i "$drive" | awk -F: '/Device Model|Model Number/ {print $2}' | xargs)
serial=$(sudo smartctl -i "$drive" | awk -F: '/Serial Number/ {print $2}' | xargs)
[[ -z "$model" ]] && model="N/A"
[[ -z "$serial" ]] && serial="N/A"
# Get power-on hours
power_on_hours=$(sudo smartctl -A "$drive" | awk '/Power_On_Hours|Power-On Hours/ {print $10}')
[[ -z "$power_on_hours" ]] && power_on_hours="N/A"
# Get last test entry (line #1)
last_test=$(sudo smartctl -l selftest "$drive" | grep "^# 1")
if [[ -z "$last_test" ]]; then
continue
fi
# Parse test details
test_type=$(echo "$last_test" | awk '{print $3}')
test_status=$(echo "$last_test" | awk '{for (i=5; i<=NF; i++) printf $i " "; print ""}' | xargs)
test_hours=$(echo "$last_test" | awk '{print $(NF-1)}')
# Calculate difference if possible
if [[ "$power_on_hours" != "N/A" && "$test_hours" != "" ]]; then
difference=$((power_on_hours - test_hours))
else
difference="N/A"
fi
# Determine result more accurately
if [[ "$test_status" =~ "Self-test routine in progress" ]] || [[ "$test_status" =~ "in progress" ]]; then
result="In progress"
elif [[ "$test_status" =~ "Completed" ]]; then
result="PASSED"
else
result="FAILED ($test_status)"
fi
# Print row
printf "%-8s %-20s %-20s %-10s %-12s %-12s %-10s %-20s\n" \
"${drive##*/}" "$model" "$serial" "$power_on_hours" "$test_hours" "$difference" "$test_type" "$result"
done
Next one “smart_drive_temp_info.zsh” shows temperatures in a table format
#!/bin/zsh
# Print header
printf "%-8s %-20s %-20s %-10s %-12s\n" "Disk" "Model" "Serial" "On_Hours" "Temperature (°C)"
printf "%-8s %-20s %-20s %-10s %-12s\n" "--------" "--------------------" "--------------------" "--------" "--------------"
# Get all disk devices
drives=($(lsblk -dno NAME,TYPE | awk '$2=="disk" {print "/dev/" $1}'))
for drive in $drives; do
# Skip if SMART not available
if ! sudo smartctl -i "$drive" >/dev/null 2>&1; then
continue
fi
# Get model and serial
model=$(sudo smartctl -i "$drive" | awk -F: '/Device Model|Model Number/ {print $2}' | xargs)
serial=$(sudo smartctl -i "$drive" | awk -F: '/Serial Number/ {print $2}' | xargs)
[[ -z "$model" ]] && model="N/A"
[[ -z "$serial" ]] && serial="N/A"
# Get Power-On Hours
power_on_hours=$(sudo smartctl -A "$drive" | awk '/Power_On_Hours|Power-On Hours/ {print $10}')
[[ -z "$power_on_hours" ]] && power_on_hours="N/A"
# Get Temperature
temperature=$(sudo smartctl -A "$drive" | \
awk '/Temperature_Celsius|Temperature_Internal|Temperature Composite/ {print $10}' | head -n1)
if [[ -z "$temperature" ]]; then
temperature=$(sudo smartctl -A "$drive" | awk '/Temperature:/ {print $2}' | head -n1)
fi
[[ -z "$temperature" ]] && temperature="N/A"
# Output row
printf "%-8s %-20s %-20s %-10s %-12s\n" "${drive##*/}" "$model" "$serial" "$power_on_hours" "$temperature"
done
Update 1: added “smart_drive_temp_info.zsh”
Update 2: added Model and Serial columns to the output in “smart_test_summary.zsh”
Update 3: “smart_test_summary.zsh” was showing “FAILED (Self-test)” for a drive that runs a test at the moment, now it shows “In progress” for such drive.