From adrian@mail.tovaris.com  Sun Sep  9 15:42:03 2001
Return-Path: <adrian@mail.tovaris.com>
Received: from tovaris.com (fw-an0.tovaris.com [209.145.84.34])
	by hub.freebsd.org (Postfix) with ESMTP id BFB2A37B405
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  9 Sep 2001 15:41:59 -0700 (PDT)
Received: (qmail 10653 invoked by uid 0); 9 Sep 2001 21:41:27 -0000
Received: from mail.tovaris.com (HELO atf.intranet) (209.145.84.38)
  by oldmail.intranet with SMTP; 9 Sep 2001 21:41:27 -0000
Received: (from adrian@localhost)
	by atf.intranet (8.11.6/8.11.6) id f89Mgit06867;
	Sun, 9 Sep 2001 18:42:44 -0400 (EDT)
	(envelope-from adrian)
Message-Id: <200109092242.f89Mgit06867@atf.intranet>
Date: Sun, 9 Sep 2001 18:42:44 -0400 (EDT)
From: Adrian Filipi-Martin <adrian@ubergeeks.com>
Reply-To: Adrian Filipi-Martin <adrian@ubergeeks.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: periodic script output to a file always appends
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30471
>Category:       bin
>Synopsis:       periodic script output to a file always appends
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brian
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 09 15:50:01 PDT 2001
>Closed-Date:    Tue Jun 29 10:08:41 GMT 2004
>Last-Modified:  Tue Jun 29 10:08:41 GMT 2004
>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:
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Mon Sep 10 03:47:21 PDT 2001 
Responsible-Changed-Why:  
I'll look after this 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30471 

From: Brian Somers <brian@freebsd-services.com>
To: Adrian Filipi-Martin <adrian@ubergeeks.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, brian@freebsd-services.com
Subject: Re: bin/30471: periodic script output to a file always appends 
Date: Mon, 10 Sep 2001 11:46:56 +0100

 > >Number:         30471
 > >Category:       bin
 > >Synopsis:       periodic script output to a file always appends
 
 Can the same functionality not be had by setting the _output 
 variables as suggested in periodic.conf(5) ?  newsyslog(8) then gives 
 all the rotation and compression flexibility that people might want.
 -- 
 Brian <brian@freebsd-services.com>                <brian@Awfulhak.org>
       http://www.freebsd-services.com/        <brian@[uk.]FreeBSD.org>
 Don't _EVER_ lose your sense of humour !      <brian@[uk.]OpenBSD.org>
 
 
State-Changed-From-To: open->feedback 
State-Changed-By: brian 
State-Changed-When: Mon Sep 17 15:07:01 PDT 2001 
State-Changed-Why:  
Awaiting feedback from original submitter 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30471 

From: Adrian Filipi-Martin <adrian@ubergeeks.com>
To: Brian Somers <brian@freebsd-services.com>
Cc: <FreeBSD-gnats-submit@FreeBSD.ORG>
Subject: Re: bin/30471: periodic script output to a file always appends 
Date: Mon, 17 Sep 2001 21:58:17 -0400 (EDT)

 	Sorry about the slow feedback.  I hald composed this and let it sit
 for a few days due to my work load. :-(
 
 On Mon, 10 Sep 2001, Brian Somers wrote:
 
 > > >Number:         30471
 > > >Category:       bin
 > > >Synopsis:       periodic script output to a file always appends
 >
 > Can the same functionality not be had by setting the _output
 > variables as suggested in periodic.conf(5) ?  newsyslog(8) then gives
 > all the rotation and compression flexibility that people might want.
 
 	Not quite.  newsyslog is very limited in its ability to rename
 files.  Being able to have monthly logs named with their month as part of
 their names just isn't possible through just newsyslog.  You can get pretty
 close though with the right options to newsyslog, but if you say keep 31
 daily logs, who know which one will hold the log for the first of the
 month.  6 moths later the first might be in daily.15.
 
 	My initial goal was to just have separate runs kept in separate
 logs for each log type and have it be obvious which day went into which
 file, so don't let my fancy use of $(date) in the *_output variables cloud
 the situation.  It's just a nicety if you want to use something like
 '$(date +%b)'.  Being able to maintain the logfiles and rotate them in a
 single place isn't such a bad thing IMHO.  If you change the logfile names,
 you need to change newsyslog.conf as well.
 
 	All in all it can be argued that we have 6 of one and half a dozen
 of the other, so I won't really press the issue.  I'm still rolling the
 patch into a base-line appliance based off of FreeBSD because it's agreeable
 to me.
 
 	Adrian
 --
 [ adrian@ubergeeks.com ]
 
 
 
State-Changed-From-To: feedback->closed 
State-Changed-By: brian 
State-Changed-When: Tue Jun 29 10:00:37 GMT 2004 
State-Changed-Why:  
I don't think that clobbering output files is the right way to go on this. 

Ultimately, the same functionality can be obtained by having a separate 
cron job that runs after daily/weekly/montly runs and ``handles'' the log 
file, truncating it after it's been handled. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30471 
>Unformatted:
