From owner-freebsd-questions Thu Dec 5 7:30:12 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9F90F37B401 for ; Thu, 5 Dec 2002 07:30:10 -0800 (PST) Received: from catv-50622a7a.nyircatv.broadband.hu (catv-50622a7a.nyircatv.broadband.hu [80.98.42.122]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1D53143ECF for ; Thu, 5 Dec 2002 07:30:09 -0800 (PST) (envelope-from andrew@kronos.HomeUnix.com) Received: from slave.east.ath.cx (witch@slave.east.ath.cx [10.1.1.1]) by catv-50622a7a.nyircatv.broadband.hu (8.12.6/8.12.6) with ESMTP id gB5FTvqp068285 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 5 Dec 2002 16:30:02 +0100 (CET) (envelope-from andrew@east.ath.cx) Date: Thu, 5 Dec 2002 16:29:57 +0100 (CET) From: Andrew Prewett Reply-To: Andrew Prewett To: freebsd-questions@FreeBSD.ORG Subject: Re: run command on logfile before it's rotated In-Reply-To: <1039067690.298.18.camel@asa.gascom.net.ru> Message-ID: <20021205154105.E39554-100000@slave.east.ath.cx> References: <93B9E916-07D2-11D7-B076-0003936CEB72@garbage.dk> <20021204220240.GY467@sub21-156.member.dsl-only.net> <1039067690.298.18.camel@asa.gascom.net.ru> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Today Akifyev Sergey wrote: > On Thu, 2002-12-05 at 01:02, Nathan Kinkade wrote: > > On Wed, Dec 04, 2002 at 10:51:43PM +0100, Thomas von Hassel wrote: > > > I've got my system set up to rotate the maillog every day at midnight. > > > What do i do if i want to run a command on the logfile just before it's > > > rotated ? > > > > > > /thomas > > > -- > > > Thomas von Hassel > > > DarX @ irc > > > darxmac @ AIM/iChat > > > Powered by inkwell...! > > > > How about just setting a cron job to run some reasonable period prior > > to newsyslog being run? > > It's incorrect way to do things, because some entries could be added to > syslog _after_ the command is run, but _before_ newsyslog. Instead you > should call some script via cron with crontab entry like this: > > # rotate log files every hour, if necessary > 0 * * * * root /usr/bin/lock_script.sh > > And the script must contain something like: > > #!/bin/sh > for $STR in `cat /etc/newsyslog.conf |grep -v '^[:space:]*#.*$'|cut > -f1`; do > lockf "${STR}" newsyslog.sh "${STR}" > done This is _advisory_ lock, not _mandatory_. Syslogd could write to the file happily while `your_command' is running or/and between `your_command' and newsyslog. Maybe this is a little closer (not tested): kill -17 ; my_scrypt; newsyslog; kill -19 Ie.: STOP syslogd; run the script(s); rotate logs; CONTinue syslogd. But if there is to much logging between the two signals, then messages could be lost. -andrew > > The newsyslog.sh should contain: > > #!/bin/sh > your_command "${1}" > newsyslog "${1}" > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message