ports/129985: [patch] sysutils/smartmontools fixes to periodic script
Alex Kozlov
spam at rm-rf.kiev.ua
Sun Dec 28 03:30:01 UTC 2008
>Number: 129985
>Category: ports
>Synopsis: [patch] sysutils/smartmontools fixes to periodic script
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun Dec 28 03:30:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Alex Kozlov
>Release: FreeBSD 7.1
>Organization:
private
>Environment:
>Description:
Some fixes for periodic script:
- Remove use of temporary file.
- Remove daily_status_smart_enable as it alway true if daily_status_smart_devices set.
- Fix return status handling. Change bitmask to 8 (as described in man smartctl)
and change rc from 2 (bad config) to 3 (must not be masked) in case of disk failing.
- Rename script to 343.smart for consistency with other periodic scripts.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
Index: sysutils/smartmontools/files/smart.in
@@ -4,6 +4,43 @@
# $FreeBSD: ports/sysutils/smartmontools/files/smart.in,v 1.1 2008/12/19 13:14:29 pav Exp $
#
+#
+# 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
@@ -12,41 +49,26 @@
smartctl=%%PREFIX%%/sbin/smartctl
: ${daily_status_smartctl_flags="-H"}
: ${daily_status_smartctl_extra_status_flags="-a"}
-# no default for ${daily_status_smart_devices}
-if [ -z "${daily_status_smart_devices}" ]; then
- : ${daily_status_smart_enabled="NO"}
-else
- : ${daily_status_smart_enabled="YES"}
-fi
-trim_junk="tail -n +4"
+rc=0
-tmpfile="$(mktemp /var/run/daily.XXXXXXXX)"
-trap "rm -f ${tmpfile}" 0 1 3 15
+# no default for ${daily_status_smart_devices}
+if [ -n "${daily_status_smart_devices}" ]; then
+ trim_junk="tail -n +4"
-rc=0
-case "${daily_status_smart_enable}" in
- [Nn][Oo])
- ;;
- *)
- for device in ${daily_status_smart_devices}; do
- if [ -e ${device} ]; then
- echo
- echo "Checking health of ${device}:"
- echo
- ${smartctl} ${daily_status_smartctl_flags} ${device} > "${tmpfile}"
- status=$?
- if [ $((status & 3)) -ne 0 ]; then
- rc=2
- ${trim_junk} "${tmpfile}"
- elif [ $status -ne 0 ]; then
- rc=1
- ${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
- else
- ${trim_junk} "${tmpfile}"
- fi
+ for device in ${daily_status_smart_devices}; do
+ if [ -e ${device} ]; then
+ echo
+ echo "Checking health of ${device}:"
+ echo
+ run_status ${smartctl} ${daily_status_smartctl_flags} ${device} \| ${trim_junk}
+ if [ $((pipestatus_1 & 8)) -ne 0 ]; then
+ rc=3
+ elif [ $pipestatus_1 -ne 0 ]; then
+ rc=1
+ ${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
fi
- done
- ;;
-esac
+ fi
+ done
+fi
exit "$rc"
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list