Lines 4-9
Link Here
|
4 |
# $FreeBSD: ports/sysutils/smartmontools/files/smart.in,v 1.1 2008/12/19 13:14:29 pav Exp $ |
4 |
# $FreeBSD: ports/sysutils/smartmontools/files/smart.in,v 1.1 2008/12/19 13:14:29 pav Exp $ |
5 |
# |
5 |
# |
6 |
|
6 |
|
|
|
7 |
# |
8 |
# Stolen from comp.unix.shell FAQ Q11 |
9 |
# (http://cfaj.freeshell.org/shell/cus-faq-2.html#11) |
10 |
# |
11 |
run_status() { |
12 |
local j com k l a |
13 |
j=1 |
14 |
while eval "\${pipestatus_$j+:} false"; do |
15 |
unset pipestatus_$j |
16 |
j=$(($j+1)) |
17 |
done |
18 |
j=1 com= k=1 l= |
19 |
for a; do |
20 |
if [ "x$a" = 'x|' ]; then |
21 |
com="$com { $l "'3>&- |
22 |
echo "pipestatus_'$j'=$?" >&3 |
23 |
} 4>&- |' |
24 |
j=$(($j+1)) l= |
25 |
else |
26 |
l="$l \"\$$k\"" |
27 |
fi |
28 |
k=$(($k+1)) |
29 |
done |
30 |
com="$com $l"' 3>&- >&4 4>&- |
31 |
echo "pipestatus_'$j'=$?"' |
32 |
exec 4>&1 |
33 |
eval "$(exec 3>&1; eval "$com")" |
34 |
exec 4>&- |
35 |
j=1 |
36 |
while eval "\${pipestatus_$j+:} false"; do |
37 |
eval "[ \$pipestatus_$j -eq 0 ]" || return 1 |
38 |
j=$(($j+1)) |
39 |
done |
40 |
return 0 |
41 |
} |
42 |
|
43 |
|
7 |
if [ -r /etc/defaults/periodic.conf ]; then |
44 |
if [ -r /etc/defaults/periodic.conf ]; then |
8 |
. /etc/defaults/periodic.conf |
45 |
. /etc/defaults/periodic.conf |
9 |
source_periodic_confs |
46 |
source_periodic_confs |
Lines 12-52
Link Here
|
12 |
smartctl=%%PREFIX%%/sbin/smartctl |
49 |
smartctl=%%PREFIX%%/sbin/smartctl |
13 |
: ${daily_status_smartctl_flags="-H"} |
50 |
: ${daily_status_smartctl_flags="-H"} |
14 |
: ${daily_status_smartctl_extra_status_flags="-a"} |
51 |
: ${daily_status_smartctl_extra_status_flags="-a"} |
15 |
# no default for ${daily_status_smart_devices} |
52 |
rc=0 |
16 |
if [ -z "${daily_status_smart_devices}" ]; then |
|
|
17 |
: ${daily_status_smart_enabled="NO"} |
18 |
else |
19 |
: ${daily_status_smart_enabled="YES"} |
20 |
fi |
21 |
trim_junk="tail -n +4" |
22 |
|
53 |
|
23 |
tmpfile="$(mktemp /var/run/daily.XXXXXXXX)" |
54 |
# no default for ${daily_status_smart_devices} |
24 |
trap "rm -f ${tmpfile}" 0 1 3 15 |
55 |
if [ -n "${daily_status_smart_devices}" ]; then |
|
|
56 |
trim_junk="tail -n +4" |
25 |
|
57 |
|
26 |
rc=0 |
58 |
for device in ${daily_status_smart_devices}; do |
27 |
case "${daily_status_smart_enable}" in |
59 |
if [ -e ${device} ]; then |
28 |
[Nn][Oo]) |
60 |
echo |
29 |
;; |
61 |
echo "Checking health of ${device}:" |
30 |
*) |
62 |
echo |
31 |
for device in ${daily_status_smart_devices}; do |
63 |
run_status ${smartctl} ${daily_status_smartctl_flags} ${device} \| ${trim_junk} |
32 |
if [ -e ${device} ]; then |
64 |
if [ $((pipestatus_1 & 8)) -ne 0 ]; then |
33 |
echo |
65 |
rc=3 |
34 |
echo "Checking health of ${device}:" |
66 |
elif [ $pipestatus_1 -ne 0 ]; then |
35 |
echo |
67 |
rc=1 |
36 |
${smartctl} ${daily_status_smartctl_flags} ${device} > "${tmpfile}" |
68 |
${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk} |
37 |
status=$? |
|
|
38 |
if [ $((status & 3)) -ne 0 ]; then |
39 |
rc=2 |
40 |
${trim_junk} "${tmpfile}" |
41 |
elif [ $status -ne 0 ]; then |
42 |
rc=1 |
43 |
${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk} |
44 |
else |
45 |
${trim_junk} "${tmpfile}" |
46 |
fi |
47 |
fi |
69 |
fi |
48 |
done |
70 |
fi |
49 |
;; |
71 |
done |
50 |
esac |
72 |
fi |
51 |
|
73 |
|
52 |
exit "$rc" |
74 |
exit "$rc" |