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

Ok, Im trying to run a program on another server using Net::SSH::Perl. This program requires input, I have no trouble running simple commands like "ls -lah /blah/". Is there a way to provide Net::SSH::Perl with the input the program is going to need.

For example I might run the program getInfo.pl which prompts for the following information:

Whats your first name:
Whats your middle name:
Whats your last name:

Does anyone know how to do this, my code is below.

use Net::SSH::Perl; my $user = "testuser"; my $pass = "testpass"; my $ssh = Net::SSH::Perl->new("10.10.10.10"); $ssh->login($user,$pass); $cmd = "getInfo.pl"; ($out, $err, $exit) = $ssh->cmd($cmd); print $out;

20031228 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: Trouble with Net::SSH::Perl
by duct_tape (Hermit) on Dec 28, 2003 at 18:44 UTC

    cmd takes an optional second argument that is a string that contains stdin. Perhaps that will work for you? I haven't tested this, but I thought i'd throw out the possibility since there are not any other replies.

    $stdin = "first name\n"; $stdin .= "middle name\n"; $stdin .= "last name\n"; ($out, $err, $exit) = $ssh->cmd($cmd, $stdin);

    Brad

Re: Trouble with Net::SSH::Perl
by jcpunk (Friar) on Dec 29, 2003 at 03:16 UTC
    unfortunatly i cannot seem to connect to the mirror of the math/crypto part to download it, but after looking over the documentation and having played a bit with Expect and Net::Telnet I think that you may want to check and make sure the following options are working correctly..... sorry i cannot be of more help.

    Looks like it might help: use_pty = 1

    From the doc :

    $ssh->shell

    Opens up an interactive shell on the remote machine and connects it to your STDIN. This is most effective when used with a pseudo tty; otherwise you won't get a command line prompt, and it won't look much like a shell. For this reason--unless you've specifically declined one--a pty will be requested from the remote machine, even if you haven't set the use_pty argument to new (described above). This is really only useful in an interactive program. In addition, you'll probably want to set your terminal to raw input before calling this method. This lets Net::SSH::Perl process each character and send it off to the remote machine, as you type it.

    There may be some use for this dispite a lack of interactivity... sometimes a program wants to send stuff in an 'interactive' way even though it isnt interactive

    sorry i cant seem to install this to play around with it.


    jcpunk
    all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)