summaryrefslogtreecommitdiff
path: root/sysutils/smartmontools/files/smart.in
blob: 407467bd5db3fcab7c29d63de4d66fcbb922cea4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# This script is in the public domain.  Original author: Garrett Wollman
#
# $FreeBSD$
#

#
# Stolen from comp.unix.shell FAQ Q11
# (http://cfaj.freeshell.org/shell/cus-faq-2.html#11)
#
run_status() {
		local j com k l a
		j=1
		while eval "\${pipestatus_$j+:} false"; do
			unset pipestatus_$j
			j=$(($j+1))
		done
		j=1 com= k=1 l=
	    for a; do
			if [ "x$a" = 'x|' ]; then
				com="$com { $l "'3>&-
							echo "pipestatus_'$j'=$?" >&3
						  } 4>&- |'
				j=$(($j+1)) l=
			else
				l="$l \"\$$k\""
			fi
		k=$(($k+1))
		done
		com="$com $l"' 3>&- >&4 4>&-
			echo "pipestatus_'$j'=$?"'
		exec 4>&1
		eval "$(exec 3>&1; eval "$com")"
		exec 4>&-
		j=1
		while eval "\${pipestatus_$j+:} false"; do
			eval "[ \$pipestatus_$j -eq 0 ]" || return 1
			j=$(($j+1))
		done
		return 0
}


if [ -r /etc/defaults/periodic.conf ]; then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

smartctl=%%PREFIX%%/sbin/smartctl
: ${daily_status_smartctl_flags="-H"}
: ${daily_status_smartctl_extra_status_flags="-a"}
rc=0

# no default for ${daily_status_smart_devices}
if [ -n "${daily_status_smart_devices}" ]; then
	for device in ${daily_status_smart_devices}; do
		if [ -e ${device} ]; then
			echo 
			echo "Checking health of ${device}:"
			run_status ${smartctl} ${daily_status_smartctl_flags} ${device} \| \
			grep 'SMART overall-health self-assessment test result'
			if [ $((pipestatus_1 & 3)) -ne 0 ]; then
				rc=2
				${smartctl} ${daily_status_smartctl_flags} ${device}
			elif [ $pipestatus_1 -ne 0 ]; then
				rc=3
				echo
				${smartctl} ${daily_status_smartctl_extra_status_flags} ${device}
			fi
		fi
	done
fi

exit "$rc"