使用命名管道通过 Perl 解析系统日志?
我正在尝试编写一个脚本,该脚本将通过网络抓取日志并解析它们以获取相关信息并执行某些操作(如果存在严重问题,则发送电子邮件;如果是警告,则只需写入日志文件)。我正在使用带有 syslogd 的 AIX 机器来处理日志。现在它像往常一样执行,将所有日志写入文件......很多文件。
有人建议我使用 Perl 和命名管道来实现该脚本。我刚刚花了一些时间阅读命名管道,发现它们非常有趣。然而,我对在这种情况下信息“流”应该如何工作以及如何让 perl 处理它感到困惑。
例如,我应该在脚本之外创建一个 fifo 并告诉 syslogd 默认写入它并让我的脚本在另一端解析它吗? Perl 可以做到这一点吗?(对于你们系统管理员来说)这是一个明智/可能的选择吗?
这是我第一次接触 Perl 和命名管道。
I'm trying to write a script that will grab logs across a network and parse them for relevant information and perform some action (email if there's a critical issue, simply write to a log file if its a warning). I am using an AIX machine with syslogd to process the logs. Right now it is performing like usual, writing all logs to files ... a lot of files.
I was advised to use Perl and Named Pipes to implement the script. I've just spent some time reading up on named pipes and I find them quite fascinating. However, I'm stumped as to how the "flow" of information should work in this situation and how to make perl handle it.
For example, should I create a fifo outside of the script and tell syslogd to write to it by default and have my script on the other end parsing it? Can Perl do that and (for you sysadmins) is this a smart/possible option?
This is my first encounter with Perl and with named pipes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你当然可以在 Perl 中创建一个 命名管道,尽管在我看来,对于你想要做什么,最好按照你的建议在perl之外创建命名管道,然后让syslogd写入它,并从perl读取管道。
我不太了解 AIX,但这可以用于创建管道(源):
要让 syslogd 写入它,请在
/var/adm/syslog.pipe
中定义:然后:
您还可以将所有这些内容放入 Perl 脚本中:以防管道执行此操作不存在或者 syslogd 没有使用它,脚本将为您安排所有必需的内容。
如果您需要更多帮助,也许您可以提供一些有关您正在尝试执行的操作的更多详细信息。
You can surely create a named pipe in Perl, although it seems to me that for what you are trying to do, it is better to create the named pipe outside of perl, as you are suggesting, and then have syslogd write to it, and read the pipe from perl.
I don't know very well AIX, but this could do for creating a pipe (source):
To have syslogd write to it, define this in
/var/adm/syslog.pipe
:Then:
You could also put all this stuff into your perl script: in case the pipe did not exist or syslogd were not using it, the script would arrange all required things for you.
Possibly you could provide some more details as to what you are trying to do, if you need more help.