Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Sep 2009 15:39:10 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-stable@FreeBSD.ORG, ferdinand.goldmann@jku.at
Subject:   Re: newsyslog can't execute command?
Message-ID:  <200909161339.n8GDdATZ042705@lurza.secnetix.de>
In-Reply-To: <4AAFA47F.6020701@jku.at>

next in thread | previous in thread | raw e-mail | index | archive | help
Ferdinand Goldmann wrote:
 > Have I overlooked something, or is it not possible with newsyslog to run a
 > certain command after log rotation? :-(

That's correct.

A simple workaround is to write a small shell script that
stores its PID in a file, then runs in the background and
waits for a signal.  It's a hack, but it works.

Basically, something like this will do:

 #!/bin/sh -
 echo $$ > /var/run/loghandler-foo.pid
 while :; do
 	kill -STOP $$
 	...
 	do whatever you want with the log file
 	...
 done

Make sure that shell script is run in the background
during system boot.

The newsyslog.conf entry should look like this:

/var/log/foo.log     644  3  100  *  B  /var/run/loghandler-foo.pid 19

The important thing is the number "19" at the end, which
will cause newsyslog to send SIGCONT to the shell script
after it has rotated the log file.

Alternatively you can also use the shell's built-in "trap"
command to use different signals.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"What is this talk of 'release'?  We do not make software 'releases'.
Our software 'escapes', leaving a bloody trail of designers and quality
assurance people in its wake."



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