£okì has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I know it's not completely correct but I'm using 'open' to run system commands like /usr/bin/ssh. as below
open (RESULT, "/usr/bin/ssh -l root " . $host . " 'httpd startssl'|"); while (<RESULT>){ print $_; } close RESULT;
This works GREAT as long as I'm working on servers for which I have a RSA or DSA key for. However, if I'm working on password based servers, I need a way to put the password in there. I know I could use Net::SSH or something of that sort however it's really slow and tends to be a memory hog. Any suggestions, maybe expect? I'm not sure.

Replies are listed 'Best First'.
Re: Opening Linux Commands
by tirwhan (Abbot) on Jan 27, 2006 at 07:23 UTC

    Have you tried Net::SSH2? Other than that, please try "Search" and "Supersearch" before posting a question, this problem had been discussed multiple times in the past.


    There are ten types of people: those that understand binary and those that don't.
      As I said in my messege I've used Net::SSH (I've used Net::SSH2 as well, it's got the same issues) this does seem to help though. Thanks, a supersearch I did, I just obviously didn't use the correct search terms.
Re: Opening Linux Commands
by glasswalk3r (Friar) on Jan 27, 2006 at 11:32 UTC

    The Expect module should help you when it's necessary to pass the password. Of course, I'm considering that the ssh program does not have an option to receive the password on the command line.

    Another option is that you use IPC::Open2 or IPC::Open3 to execute the program, both can read and write at the program STDOUT and STDIN, respectively.

    Anyway... why don't you keep using the RSA (or DSA) keys?

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

      The problem with using one of the IPC:: modules rather than Expect is that many programs which want to read a password will reopen the process' controlling terminal (i.e. /dev/tty) rather than using STDIN and bypass them completely. Since Expect runs the child process on a pty it can handle this case.

      Heh, because it's not my choice. All MY servers use RSA keys. I just need it to work with some servers of lesser quality as well.