From owner-freebsd-bugs Sun Sep 9 15:50: 9 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4ABBE37B409 for ; Sun, 9 Sep 2001 15:50:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f89Mo1G32669; Sun, 9 Sep 2001 15:50:01 -0700 (PDT) (envelope-from gnats) Received: from tovaris.com (fw-an0.tovaris.com [209.145.84.34]) by hub.freebsd.org (Postfix) with ESMTP id BFB2A37B405 for ; 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 Reply-To: Adrian Filipi-Martin To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/30471: periodic script output to a file always appends Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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