From owner-freebsd-stable Mon Nov 13 7:17:16 2000 Delivered-To: freebsd-stable@freebsd.org Received: from yertle.kciLink.com (yertle.kciLink.com [208.184.13.195]) by hub.freebsd.org (Postfix) with ESMTP id AD42F37B4CF for ; Mon, 13 Nov 2000 07:17:11 -0800 (PST) Received: from onceler.kciLink.com (onceler.kciLink.com [208.184.13.196]) by yertle.kciLink.com (Postfix) with ESMTP id 0102D2E449 for ; Mon, 13 Nov 2000 10:17:10 -0500 (EST) Received: (from khera@localhost) by onceler.kciLink.com (8.11.1/8.11.1) id eADFHA518917; Mon, 13 Nov 2000 10:17:10 -0500 (EST) (envelope-from khera) From: Vivek Khera MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14864.1526.589801.965839@onceler.kciLink.com> Date: Mon, 13 Nov 2000 10:17:10 -0500 To: freebsd-stable@FreeBSD.org Subject: Re: periodic and 310.accounting In-Reply-To: <200011122305.eACN5jB05000@hak.lan.Awfulhak.org> References: <20001112161701.A10495@futuresouth.com> <200011122305.eACN5jB05000@hak.lan.Awfulhak.org> X-Mailer: VM 6.80 under 21.1 (patch 12) "Channel Islands" XEmacs Lucid Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >>>>> "BS" == Brian Somers writes: BS> I think it'd be nice if newsyslog could be told to ``just rotate this BS> file with this number of backups with{,out} compression''. It can be BS> given a file name, but still needs the config file to know when to BS> rotate.... Here's a script I've used on other systems to rotate logs on demand. It can optionally send a signal and then optionally compress the file. I call it "logrotate" ;-) --cut here-- #! /usr/bin/perl use strict; # Time-stamp: "12 July 1999, 15:55:00 (khera@kciLink.com)" # $Id: logrotate.perl,v 1.3 1999/07/12 19:55:16 khera Exp $ # rotate log files and optionally send a signal (default is HUP) to # the specified process ID, then optionally compress the newly rotated # log file. # Copyright 1999 Vivek Khera use constant USAGE => "usage:rotatelogs [-z] [-p PID] [-s SIG] -r N file...\n"; use IO::File; use Getopt::Std; my %opt = (); getopts('zp:s:r:',\%opt); scalar(@ARGV) or die USAGE; # are there files specified? die USAGE unless $opt{'r'}; # first rotate the files foreach my $file (@ARGV) { rotate ($file,$opt{'r'}); } # now send the signal, if necessary. Default signal is HUP. if ($opt{'p'}) { my $sig = $opt{'s'} || 'HUP'; unless (kill $sig, $opt{'p'}) { warn "Failed to send $sig to $opt{'p'}\n"; } } # and finally compress the newly rotated files, if requested if ($opt{'z'}) { foreach my $file (@ARGV) { system "gzip $file.0"; } } # rotate the named log file and archive $howmany old versions. eg, # rotate("foo",3); # will move foo -> foo.0 -> foo.1 -> foo.2 -> foo.3 # and remove old foo.3, then create empty foo. sub rotate ($$) { my($file,$howmany) = @_; my($cur); return if ($howmany < 0); unlink ("$file.$howmany","$file.$howmany.gz"); # remove topmost one. for ($cur = $howmany; $cur > 0; $cur--) { my $prev = $cur - 1; rename("$file.$prev","$file.$cur") if (-f "$file.$prev"); rename("$file.$prev.gz","$file.$cur.gz") if (-f "$file.$prev.gz"); } rename("$file","$file.0"); # move original one # create the new one! my $fh = new IO::File $file, O_WRONLY|O_CREAT, 0644; $fh->close(); } --cut here-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message