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.
Any 开发者_如何学JAVAidea?, I would like be able to do things with each line of apache log in real time but in another server.
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).
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.). Hopefully this has given you some ideas! nc has loads of options so you should be able to find something.
If you want to write netcat in Perl then that's a slightly different story.
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).
A very simple solution is to tail the log file from the remote host via SFTP using Net::SFTP::Foreign.
The module contains a sample script implementing the remote tail: sftp_tail.pl
精彩评论