Basically, what I am trying to accomplish here is the ability to see Net::OpenSSH log into a remote system, run commands (viewing STDOUT/STDERR from these commands), and then exit. I can easily connect to the system, capture STDERR/STDOUT, and then print them. But I'd really like to see what is happening as it is happening as if I was sitting there at my terminal typing the commands myself.

Let me try to be a bit more specific. What I'd really like is for Net::OpenSSH to spawn a shell (/bin/bash), ssh to remote server and run commands. I'd be looking first at a localhost prompt, then the ssh connection ('localhost # ssh remote_server'), possible a password prompt and the interaction that happens there (if password => 'pass' is used when creating object), and then the commands as they are passed on the remote shell and the remote prompt as well.

I haven't included any code here because I have no idea if it's even possible, thus no idea really where to start. I did create a Net::OpenSSH object and used Expect to create an interactive terminal, but I still only ended up with output... As well, I'd really rather not use Expect for this if I don't need to (i.e., the commands themselves are not interactive).

#!/usr/bin/env perl + use strict; + use warnings; + use Net::OpenSSH; + use Expect; + + my $timeout = 20; + my $ssh = Net::OpenSSH->new('walkingthecow@remote_host', password => ' +PkDDaDoES$551890'); # not really my password ;) + my ($pty, $pid) = $ssh->open2pty("ls /etc") + or die "open2pty failed: " . $ssh->error . "\n"; + + my $expect = Expect->init($pty); + $expect->raw_pty(1); + $expect->log_stdout(1); + while(<$pty>) { + print "$_" + }

In reply to Is it possible to see what Net::OpenSSH is doing? by walkingthecow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.