Subject: bin/37376: /etc/{daily,weekly,montly} shouldn't try to "dot in" {}.local
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <eschnoebelen@efjohnson.com>
List: netbsd-bugs
Date: 11/13/2007 15:30:00
>Number:         37376
>Category:       bin
>Synopsis:       /etc/{daily,weekly,monthly} attempt to "dot in" {}.local
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 13 15:30:00 +0000 2007
>Originator:     Eric Schnoebelen
>Release:        NetBSD 4.99.34
>Organization:
Eric Schnoebelen	eschnoebelen@efjohnson.com		eric@cirr.com
"He made a lot of mistakes.  But he made mistakes in good directions, so 
 eventually he got to the right answers.  I tried to imitate him, but I 
 found out that it is very difficult to make good mistakes." -- Goro Simura
>Environment:
System: NetBSD duke 4.99.34 NetBSD 4.99.34 (GENERIC.MP) #17: Sat Nov 3 07:24:10 CDT 2007 eric@egsner.cirr.com:/work/eric/NetBSD-current/obj/amd64/sys/arch/amd64/compile/GENERIC.MP amd64
Architecture: x86_64
Machine: amd64
>Description:
The administrative scripts /etc/{daily,weekly,monthly} contain the following
construct:
	. /etc/weekly.local > $TMP 2>&1

Which doesn't work, as the "." (dot)  operator doesn't allow/permit
redirection of it's output.. So, trying to run the local scripts failes.

>How-To-Repeat:
Write a /etc/daily.local script (doesn't have to do much) and wonder why
it doesn't run overnight..

>Fix:
remove the attempts to use the bourne shell's dot operator to execute
the script as part of the current shell.

Alternatively, if it is felt essential that the local scripts execute in
the current shell's environment, use sh(1) exec magic to redirect
standard output and standard error. eg:

[...]
if [ -f /etc/daily.local ] ; then
	# stash away stdout/err, then put them on log file
	exec 1>&10 2>&11 1> $TMP 2>&1
	. /etc/daily.local
	# put everything back.
	exec 10>&1 11>&2 10>&- 11>&-
	if [ -s "${TMP}" ] ; then
[...]

--- /var/backups/etc/daily.current	2007-10-09 03:16:40.000000000 -0500
+++ /etc/daily	2007-11-13 09:13:51.000000000 -0600
@@ -268,7 +268,7 @@
 fi
 
 if [ -f /etc/daily.local ]; then
-	. /etc/daily.local > $TMP 2>&1
+	/etc/daily.local > $TMP 2>&1
 	if [ -s $TMP ] ; then
 		printf "\nRunning /etc/daily.local:\n"
 		cat $TMP
--- /var/backups/etc/weekly.current	2007-11-13 03:15:58.000000000 -0600
+++ /etc/weekly	2007-11-13 09:13:30.000000000 -0600
@@ -90,7 +90,7 @@
 fi
 
 if [ -f /etc/weekly.local ]; then
-	. /etc/weekly.local > $TMP 2>&1
+	/etc/weekly.local > $TMP 2>&1
 	if [ -s $TMP ] ; then
 		printf "\nRunning /etc/weekly.local:\n"
 		cat $TMP
--- /var/backups/etc/monthly.current	2007-10-09 03:16:40.000000000 -0500
+++ /etc/monthly	2007-11-13 09:18:26.000000000 -0600
@@ -35,7 +35,7 @@
 # ac -p | sort -nr +1
 
 if [ -f /etc/monthly.local ]; then
-	. /etc/monthly.local > $TMP 2>&1
+	/etc/monthly.local > $TMP 2>&1
 	if [ -s $TMP ] ; then
 		printf "\nRunning /etc/monthly.local:\n"
 		cat $TMP

>Unformatted:
 	also present on 4.0_BETA?/RC?, 3.X.