Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

How to execute Net::OpenSSH remote command requiring input

by avonnieda (Novice)
on Oct 26, 2009 at 14:43 UTC ( [id://803285]=perlquestion: print w/replies, xml ) Need Help??

avonnieda has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I've got a remote command which is menu based that I need to invoke via Net::OpenSSH in a hands-off fashion. When I try to run it using the following method, it basically pegs the box and doesn't complete. I'm hoping there's a better method that someone can share with me. Here's an example of what I'm doing, which is to use "/bin/echo" to send the responses with newlines, and pipe them into the interactive program. Any insight would be appreciated.

$ssh = Net::OpenSSH->new($hostname, user => $username, master_stderr_discard => 1}
$command = "cd /usr/local/bin; /bin/echo -e \"input1\ninput2\ninput3\" | interactive_program.pl";
@out = $ssh->capture($command);

Thanks!
-Adam vonNieda

  • Comment on How to execute Net::OpenSSH remote command requiring input

Replies are listed 'Best First'.
Re: How to execute Net::OpenSSH remote command requiring input
by avonnieda (Novice) on Oct 26, 2009 at 15:00 UTC

    Never mind folks, I found a sample included in the Net::OpenSSH module distribution using Expect, that should do it.

    -Adam
Re: How to execute Net::OpenSSH remote command requiring input
by salva (Canon) on Oct 26, 2009 at 15:13 UTC
    You can feed data to the remote process using the stdin_data option as follows:
    $ssh = Net::OpenSSH->new($hostname, user => $username, master_stderr_d +iscard => 1} $command = "cd /usr/local/bin; interactive_program.pl"; @out = $ssh->capture({stdin_data => "input1\ninput2\ninput3\n"}, $comm +and);
    Though, I don't think that will solve your problem... the Expect approach seems more promising!

      Ahh, I see, didn't know about that option either. Thanks very much for the reply salva! The expect method is working great, the sample was very helpful.

      Best regards,
      -Adam

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found