3 ### Check the health of attached physical disks.
6 if [ ! -x
/usr
/sbin
/smartctl
]; then exit 0; fi
8 ## Build a list of actual disk devices according to their buses.
10 for p
in /sys
/class
/block
/*; do
11 bus
=none devtype
=none idtype
=none
12 while read code assg
; do
14 DEVNAME
=*) name
=${assg#*=} ;;
15 ID_BUS
=*) bus
=${assg#*=} ;;
16 DEVTYPE
=*) devtype
=${assg#*=} ;;
17 ID_TYPE
=*) idtype
=${assg#*=} ;;
20 $(udevadm info --query=all --path=$p)
22 case "$bus,$devtype,$idtype" in
23 ata
,disk
,disk | scsi
,disk
,disk
) disks
=${disks+$disks }$name ;;
27 ## Now go through each disk.
28 for disk
in $disks; do
29 set +e
; smartctl
-qsilent
$disk; rc
=$?
; set -e
30 if (( $rc & 2 )); then continue; fi
32 if (( $rc & 8 )); then echo "W: SMART reports disk $disk failing"; fi
35 while read id attr flag value worst thresh
type upd when raw
; do
36 case "$id" in *[!0-9]*) continue ;; ?
*) ;; *) continue ;; esac
38 case "$value" in 0*?
) value
=${value#0} ;; *) break ;; esac;
41 case "$thresh" in 0*?
) thresh
=${thresh#0} ;; *) break ;; esac;
43 case "$attr,$raw,$when" in
44 Current_Pending_Sector
,*[!0]*,*)
45 echo "W: disk $disk has $raw pending sector(s)"
47 Offline_Uncorrectable
,*[!0]*,*)
48 echo "W: disk $disk has $raw offline-uncorrectable sector(s)"
51 echo "W: disk $disk attribute $attr failing (value = $raw)"
54 if (( $value < $thresh )); then
55 echo "I: disk $disk attribute $attr below thresh (value = $raw)"