Bug 129985 - [patch] sysutils/smartmontools fixes to periodic script
[patch] sysutils/smartmontools fixes to periodic script
Status: Closed FIXED
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s)
Latest
Any Any
: Normal Affects Only Me
Assigned To: pav
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-12-28 03:30 UTC by spam
Modified: 2008-12-28 09:30 UTC (History)
0 users

See Also:


Attachments
file.diff (2.55 KB, patch)
2008-12-28 03:30 UTC, spam
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description spam 2008-12-28 03:30:00 UTC
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.

Fix: Patch attached with submission follows:
Comment 1 Edwin Groothuis freebsd_committer 2008-12-28 03:30:10 UTC
Responsible Changed
From-To: freebsd-ports-bugs->pav

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 spam 2008-12-28 06:03:56 UTC
Hi, pav

More polished version:


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"
-
-tmpfile="$(mktemp /var/run/daily.XXXXXXXX)"
-trap "rm -f ${tmpfile}" 0 1 3 15
-
 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}:"
+
+# 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_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
+				${smartctl} ${daily_status_smartctl_extra_status_flags} ${device}
 			fi
-		done
-		;;
-esac
+		fi
+	done
+fi
 
 exit "$rc"
Comment 3 pav freebsd_committer 2008-12-28 09:20:41 UTC
State Changed
From-To: open->closed

Committed, thanks (the more polished version)
Comment 4 dfilter freebsd_committer 2008-12-28 09:21:03 UTC
pav         2008-12-28 09:20:51 UTC

  FreeBSD ports repository

  Modified files:
    sysutils/smartmontools Makefile 
    sysutils/smartmontools/files smart.in 
  Log:
  - Improve periodic script
  
  PR:             ports/129985
  Submitted by:   Alex Kozlov <spam@rm-rf.kiev.ua>
  
  Revision  Changes    Path
  1.35      +1 -1      ports/sysutils/smartmontools/Makefile
  1.2       +56 -34    ports/sysutils/smartmontools/files/smart.in
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"