#!/bin/bash # dbanner-title-uk: Стан дисків (SMART) # dbanner-title-en: Disk health (SMART) # dbanner-mode: cached # dbanner-interval: 21600 # Health, temperature and power-on hours of every disk; needs root and smartmontools. . "${0%/*}/lib.sh" command -v smartctl >/dev/null || exit 0 ((EUID == 0)) || exit 0 first=1 for dev in /sys/block/*; do name=${dev##*/} [[ $name == @(loop|ram|zram|sr|dm-|md)* ]] && continue out=$(smartctl -H -A -i "/dev/$name" 2>/dev/null) || [[ -n $out ]] || continue model=$(sed -n 's/^\(Device Model\|Model Number\|Product\): *//p' <<<"$out" | head -1) health=$(sed -n 's/.*\(overall-health\|Health Status\).*: *//p' <<<"$out" | head -1) temp=$(awk '/Temperature_Celsius|Airflow_Temperature/ {print $10; exit} /^Temperature:/ {print $2; exit}' <<<"$out") hours=$(awk '/Power_On_Hours/ {print $10; exit} /^Power On Hours:/ {gsub(",", "", $4); print $4; exit}' <<<"$out") [[ -n $health ]] || continue if ((first)); then echo "$Bold$(say "Стан дисків:" "Disk health:")$Off"; first=0; fi hcolor=$Green [[ $health == PASSED || $health == OK ]] || hcolor=$Red line=" /dev/$name ${model:+($model) }$hcolor$health$Off" [[ $temp =~ ^[0-9]+$ ]] && line+=", $(level "$temp" 55 70)$temp °C$Off" [[ $hours =~ ^[0-9]+$ ]] && line+=", $Cyan$hours $(say "год" "h")$Off" echo "$line" done