简体   繁体   English

Perl 尾登录服务器间

[英]Perl tail logs in between servers

I basically want to be able to send the apache log file line by line (tail) in between two servers (unidirectionally, from one two one), I want to use perl.我基本上希望能够在两台服务器之间(单向,从一到二)逐行(尾)发送 apache 日志文件,我想使用 perl。

Any idea?, I would like be able to do things with each line of apache log in real time but in another server.有什么想法吗?,我希望能够实时处理 apache 日志的每一行,但在另一台服务器上。

Thanks you!谢谢!

Not sure about Perl (you can probably wrap this up in a bit of Perl so you can manipulate the data), but netcat (or nc for short) (should be available on most systems).不确定 Perl (您可以将其包含在 Perl 中,以便您可以操作数据),但 netcat(或简称 nc)(应该在大多数系统上可用)。

On one server在一台服务器上

tail -f filename | nc -l 12345

On the other server在另一台服务器上

nc hostname 12345

Of course you can use a different port number.当然,您可以使用不同的端口号。 So I guess in Perl you would exec these commands (ssh to the remote server etc.).所以我猜在 Perl 中你会执行这些命令(ssh 到远程服务器等)。 Hopefully this has given you some ideas.希望这给了你一些想法。 nc has loads of options so you should be able to find something. nc 有很多选项,所以你应该能够找到一些东西。

If you want to write netcat in Perl then that's a slightly different story.如果您想在 Perl 中编写 netcat,那么情况就略有不同了。

You can use piped logs .您可以使用管道日志 This way your perl script will get every log line on standard input and then it's up to you, how you are going to send them (SSH, FTP, HTTP or maybe even connect to SQL etc). This way your perl script will get every log line on standard input and then it's up to you, how you are going to send them (SSH, FTP, HTTP or maybe even connect to SQL etc).

A very simple solution is to tail the log file from the remote host via SFTP using Net::SFTP::Foreign .一个非常简单的解决方案是使用Net::SFTP::Foreign通过 SFTP 从远程主机跟踪日志文件。

The module contains a sample script implementing the remote tail: sftp_tail.pl该模块包含一个实现远程尾部的示例脚本: sftp_tail.pl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM