Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Sep 2001 18:42:44 -0400 (EDT)
From:      Adrian Filipi-Martin <adrian@ubergeeks.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/30471: periodic script output to a file always appends
Message-ID:  <200109092242.f89Mgit06867@atf.intranet>

next in thread | raw e-mail | index | archive | help


>Number:         30471
>Category:       bin
>Synopsis:       periodic script output to a file always appends
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 09 15:50:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Adrian Filipi-Martin
>Release:        FreeBSD 4.4-RC i386
>Organization:
Ubergeeks Consulting
>Environment:
System: FreeBSD atf.intranet 4.4-RC FreeBSD 4.4-RC #22: Mon Aug 27 13:29:36 EDT 2001 root@atf.intranet:/home/obj/usr/src/sys/ATF i386

>Description:

	If any of the *_output variables are set to files in
	periodic.conf, they will always append to the file.  This
	forces you to truncate the files through some external
	mechanism, which is cumbersome.

	It would be nice to have periodic know whether or not to
	preserve the old contents of the file by itself.  Since
	periodic.conf is just shell code, it is easy to implement
	complex self maintaining sets of logs.

	Consider the following settings in periodic.conf:

	daily_output="/var/log/periodic/daily.$(date +%d)"
	daily_output_clobber="YES"
        daily_status_security_output="/var/log/periodic/security.$(date +%d)"
        daily_status_security_output_clobber="YES"
        weekly_output="/var/log/periodic/weekly.$(date +%U)"
        weekly_output_clobber="YES"
        monthly_output="/var/log/periodic/monthly.$(date +%m)"
        monthly_output_clobber="YES"

	These settings allow local archiving of the output with
	automatic reuse of the old log files.  Dailies are kept
	for a month, weeklies and monthlies for a year.

	Note that this option opens the door to gzipping the output.
	To gzip, you must always clobber the old log file.

>How-To-Repeat:

	Set daily_output="/some/file" in periodic.conf and run
	'periodic daily' a few times to see that it always appends.
>Fix:

	Apply the attached patches to the default periodic.conf
	and periodic.sh.  For historical compatability the default
	behavior is to append.

--- periodic.conf.orig	Sun Sep  9 18:09:05 2001
+++ periodic.conf	Sun Sep  9 18:11:46 2001
@@ -28,6 +28,7 @@
 # wish to log the daily output and have the files rotated by newsyslog(8)
 #
 daily_output="root"					# user or /file
+daily_output_clobber="NO"				# truncate /file?
 daily_show_success="YES"				# scripts returning 0
 daily_show_info="YES"					# scripts returning 1
 daily_show_badconfig="NO"				# scripts returning 2
@@ -113,6 +114,7 @@
 daily_status_security_enable="YES"			# Security check
 daily_status_security_inline="NO"			# Run inline ?
 daily_status_security_output="root"			# user or /file
+daily_status_security_output_clobber="NO"		# truncate /file?
 daily_status_security_noamd="NO"			# Don't check amd mounts
 daily_status_security_nomfs="NO"			# Don't check mfs mounts
 
@@ -139,6 +141,7 @@
 # wish to log the weekly output and have the files rotated by newsyslog(8)
 #
 weekly_output="root"					# user or /file
+weekly_output_clobber="NO"				# truncate /file?
 weekly_show_success="YES"				# scripts returning 0
 weekly_show_info="YES"					# scripts returning 1
 weekly_show_badconfig="NO"				# scripts returning 2
@@ -179,6 +182,7 @@
 # wish to log the monthly output and have the files rotated by newsyslog(8)
 #
 monthly_output="root"					# user or /file
+monthly_output_clobber="NO"				# truncate /file?
 monthly_show_success="YES"				# scripts returning 0
 monthly_show_info="YES"					# scripts returning 1
 monthly_show_badconfig="NO"				# scripts returning 2

--- periodic.sh.orig	Sat Sep  8 22:09:32 2001
+++ periodic.sh	Sun Sep  9 18:08:42 2001
@@ -38,7 +38,11 @@
     # Where's our output going ?
     eval output=\$${arg##*/}_output
     case "$output" in
-    /*) pipe="cat >>$output";;
+    /*) 
+	case $(eval echo "\$${arg##*/}_output_clobber") in
+	    [Yy][Ee][Ss]) pipe="cat > $output";;
+	    *)            pipe="cat >>$output";;
+	esac;;
     "") pipe=cat;;
     *)  pipe="mail -s '$host ${arg##*/} run output' $output";;
     esac
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200109092242.f89Mgit06867>