How can I use 'newsyslog' to trigger a script everytime my log file is rolled over or rotated?

721 Views Asked by At

How can I use 'newsyslog' to trigger a script everytime my log file is rolled over or rotated? The script is a parser which collects the important information from the log and archives it.

Is using the path_to_pid_cmd_file in newsyslog.conf the only way to do something like this? The problem I have with this approach is that this means my parser script would need to always be running/sleeping in the background and I would be signalling it.

I was wondering if there was a cleaner way to do this? Just before the logfile is to be rotated, the parser script should be run and data archived after which the parser dies. And this happens each time a log file is rotated.

I did hear about 'logrotate' supporting functionality like this with the pre-rotate handler but is there a way to accomplish this with 'newsyslog' or 'syslog'.

1

There are 1 best solutions below

0
On

There unfortunately is no way to do this using newsyslog other than what you've suggested by having a dedicated process running to receive the signal.

logrotate is the most fully-featured package I've come across to do things beyond the built-in capabilities of newsyslog, but if you wanted something simpler and more DIY, I'd look at the sysutils/wait_on utility which uses kqueue to see a change.