Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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:


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

Replies are listed 'Best First'.
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.
Re: Disconnect from Remote Server
by salva (Abbot) 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!


      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/ 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";


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://862481]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2018-08-17 00:15 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (174 votes). Check out past polls.