http://www.perlmonks.org?node_id=1038428


in reply to Is it possible to see what Net::OpenSSH is doing?

Net::OpenSSH or actually the SSH protocol do not work exactly like that. There is not a remote session where you send commands and get the response back.

Instead there is a binary protocol and on top of it bidirectional IO channels can be created and remote commands or port forwarders attached to them.

In general there is no way to see the IO operations happening because there are handled directly by the master ssh program running on the background. The exception is when you use capturing methods as then, it is Net::OpenSSH who is talking at the other side.

In any case, the module has a debugging mode. For instance, setting...

$Net::OpenSSH::debug = 4|8|64;
... would give you a good idea of what is going on.

Another possibility is to pipe the output of any command through tee so that it appears on the screen and is also saved to a file:

$ssh->system({ stdout_file => ['|-', 'tee'. 'cmd_output.txt ], stderr_to_stdout => 1 }, @cmd);

Replies are listed 'Best First'.
Re^2: Is it possible to see what Net::OpenSSH is doing?
by walkingthecow (Friar) on Jun 12, 2013 at 11:21 UTC

    Hm, I was thinking with the ability to make an interactive shell with Expect, and then the ability to type/send commands and get/receive that command's output, maybe I could get that interactive shell and somehow have Net::OpenSSH type/send commands to the shell rather than me. I even tried setting master_stdout(stderr)_fh's to the pty device, but obviously that didn't work. I thought I was on to something a bit ago, but kept ending with the error 'Error: could not connect pty as controlling terminal'. Darn.

      Net::OpenSSH does not send commands to a shell.

      A possible way, quite difficult, may be to abuse the OSTracer interface that allows to run the master ssh process with strace (or your favourite OS equivalent).

      You will have to write your own tracer able to dump the IO interactions of the ssh master process to the console.

        I just realized you wrote this module. Thank you. I've been using Expect for years. I just started using Net::OpenSSH recently, and it has really made my life a lot easier. I'm looking at strace output as well as OSTracer to see what I can come up with. I will post back here with any results (i.e., don't expect me to post back here).