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