POE::Component::RemoteTail - tail to remote server's access_log on ssh connection.
use POE; use POE::Component::RemoteTail; my ( $host, $path, $user ) = @target_host_info; # spawn component my $tailer = POE::Component::RemoteTail->spawn(); # create job my $job = $tailer->job( host => $host, path => $path, user => $user, ssh_options => $ssh_options, # see POE::Component::RemoteTail::Job add_command => $add_command, # see POE::Component::RemoteTail::Job ); # prepare the postback subroutine at main POE session POE::Session->create( inline_states => { _start => sub { my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; # create postback_handler my $postback_handler = { child_stdout => $session->postback("child_stdout"), child_stderr => $session->postback("child_stderr"), child_close => $session->postback("child_close"), }; # post to execute $kernel->post( tailer => start_tail => { job => $job, postback_handler => $postback_handler } ); }, # return to here child_stdout => sub { my ( $kernel, $session, $data ) = @_[ KERNEL, SESSION, ARG1 ]; my $log = $data->[0]; my $host = $data->[1]; ... do something ...; }, child_stderr => sub { my $data = $_[ARG1]; my $error_message = $data->[0]; ... do something ...; } child_close => sub { my $data = $_[ARG1]; my $closed_host = $data->[0]; ... do something ...; } }, ); POE::Kernel->run();
POE::Component::RemoteTail provides some loop events that tailing access_log on remote host. It replaces "ssh -A user@host tail -F access_log" by the same function. ( 'tail -F' is same as 'tail --follow=name --retry')
This moduel does not allow 'PasswordAuthentication'. Use RSA or DSA keys, or you must write your Custom Engine with this module. ( ex. POE::Component::RemoteTail::CustomEngine::NetSSHPerl.pm )
Unless you prepare the 'postback_handler', PoCo::RemoteTail outputs child process's STDOUT, STDERR and closed host name.
use POE::Component::RemoteTail; my $tailer = POE::Component::RemoteTail->spawn(); my $job = $tailer->job( host => $host, path => $path, user => $user ); POE::Session->create( inlines_states => { _start => sub { $kernel->post($tailer->session_id, "start_tail" => {job => $job}); }, } ); POE::Kernel->run();
It can tail several servers at the same time.
use POE::Component::RemoteTail; my $tailer = POE::Component::RemoteTail->spawn(alias => $alias); my $job_1 = $tailer->job( host => $host1, path => $path, user => $user ); my $job_2 = $tailer->job( host => $host2, path => $path, user => $user ); POE::Session->create( inlines_states => { _start => sub { my $postback_handler = { child_stdout => $session->postback("child_stdout"), child_stderr => $session->postback("child_stderr"), child_close => $session->postback("child_close"), }; $kernel->post($alias, "start_tail" => {job => $job_1, postback_handler => $postback_handler }); $kernel->post($alias, "start_tail" => {job => $job_2, postback_handler => $postback_handler }); $kernel->delay_add("stop_tail", 10, [ $job_1 ]); $kernel->delay_add("stop_tail", 20, [ $job_1 ]); }, child_stdout => sub { my ( $kernel, $session, $data ) = @_[ KERNEL, SESSION, ARG1 ]; my $log = $data->[0]; my $host = $data->[1]; ... do something ...; }, child_stderr => sub { my $data = $_[ARG1]; my $error_message = $data->[0]; ... do something ...; } child_close => sub { my $data = $_[ARG1]; my $closed_host = $data->[0]; ... do something ...; stop_tail => sub { my ( $kernel, $session, $arg ) = @_[ KERNEL, SESSION, ARG0 ]; my $target_job = $arg->[0]; $kernel->post( $alias, "stop_tail" => {job => $target_job}); }, }, ); POE::Kernel->run();
Takeshi Miki <miki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install POE::Component::RemoteTail, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::RemoteTail
CPAN shell
perl -MCPAN -e shell install POE::Component::RemoteTail
For more information on module installation, please visit the detailed CPAN module installation guide.