每次我的日志文件翻转或轮换时,如何使用'newsyslog'来触发脚本?

时间:2022-06-18 08:40:25

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.

每次我的日志文件翻转或轮换时,如何使用'newsyslog'来触发脚本?该脚本是一个解析器,它从日志中收集重要信息并将其归档。

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.

在newsyslog.conf中使用path_to_pid_cmd_file是这样做的唯一方法吗?我对这种方法的问题是,这意味着我的解析器脚本需要始终在后台运行/休眠,我会发出信号。

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'.

我确实通过预旋转处理程序听到了'logrotate'这样的支持功能,但有没有办法用'newsyslog'或'syslog'来实现这一点。

1 个解决方案

#1


1  

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.

遗憾的是,除了你通过运行专用进程来接收信号所建议的内容之外,使用newsyslog无法做到这一点。

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.

logrotate是我在遇到newsyslog的内置功能之外做的最全功能的包,但如果你想要更简单和更多的DIY,我会看看使用kqueue看的sysutils / wait_on实用程序变化。

#1


1  

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.

遗憾的是,除了你通过运行专用进程来接收信号所建议的内容之外,使用newsyslog无法做到这一点。

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.

logrotate是我在遇到newsyslog的内置功能之外做的最全功能的包,但如果你想要更简单和更多的DIY,我会看看使用kqueue看的sysutils / wait_on实用程序变化。