#!/usr/app/TurboShell/bin/bash
# Reads the output of smartctl -A and shows what needs a look
set -euo pipefail
bad=0
while read -r id name _ _ _ _ _ _ _ raw _; do
  [[ $id =~ ^[0-9]+$ ]] || continue
  case $name in
    Reallocated_Sector_Ct | Current_Pending_Sector | Offline_Uncorrectable | UDMA_CRC_Error_Count)
      mark=ok
      if ((raw > 0)); then
        mark=LOOK
        bad=$((bad + 1))
      fi
      printf '%-5s %s %s\n' "$mark" "$name" "$raw"
      ;;
    Temperature_Celsius) echo "      temperature $raw C" ;;
    Power_On_Hours) echo "      on for $((raw / 24)) days" ;;
  esac
done
echo "$bad values need a look"
((bad == 0))
