Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Disconnect from Remote Server

by rfbits (Initiate)
on Sep 28, 2010 at 18:31 UTC ( #862481=perlquestion: print w/ replies, xml ) Need Help??
rfbits has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm using Net::SSH::Perl to connect to the remote server. After executing the below code (to get real-time output), I want the control to be returned to the client. This is required, because I want to process the output captured from the logs.

I looked at the perldocs of the module, but I did not find any subroutine that supports this feature.

#!/usr/bin/perl - w use Net::SSH::Perl; use strict; ............. ............. ............. ............. $sshRemote->register_handler("stdout", sub { my($channel, $buffer) = @_; $str = $buffer->get_str; } ($stdout, $stderr, $err) = $appRemote->cmd("tail -f /var/log/messages" +);

Thanks, Roger

Comment on Disconnect from Remote Server
Download Code
Re: Disconnect from Remote Server
by tirwhan (Abbot) on Sep 28, 2010 at 19:18 UTC

    Your system command ("tail -f") never returns, because it keeps the file open and tries to follow it forever. So "after executing the code" never happens, the code keeps running until it is killed. Try just using tail (possibly with "-n" to adjust the number of lines you get).


    All dogma is stupid.
      Thanks!
Re: Disconnect from Remote Server
by salva (Monsignor) on Sep 29, 2010 at 06:23 UTC
    For your particular example, you can use SFTP instead of running remote commands and capturing their output.

    This script from the Net::SFTP::Foreign distribution shows how to emulate a tail -f over SFTP.

      Thanks Salva!

      Hello,

      I get the following error message, when I execute the perl script:

      Undefined subroutine &Net::SFTP::Foreign::_catch_tainted_args called at /usr/lib/perl5/site_perl/5.10/Net/SFTP/Foreign.pm line 156.

      #!/usr/bin/perl use strict; use warnings; use Net::SFTP::Foreign; use Fcntl qw(SEEK_END); my ($host, $file, $user, $pwd, $port) = undef; my $sftp = Net::SFTP::Foreign->new($host, $user, $pwd, $port); $sftp->error and die "Unable to connect to remote host: ".$sftp->error +."\n";

      Thanks,

      Roger
        I have just uploaded to CPAN version 1.62 solving that problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://862481]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2014-11-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls