in reply to executing command with Net::SSH2

So are your trying to open a SSH connection on your server to a third host?

That won't work, because ssh asks for a password, and wants to read that from the terminal, not from STDIN. You can try to use Net::SSH::Expect as a workaround.

Replies are listed 'Best First'.
Re^2: executing command with Net::SSH2
by drip (Beadle) on Jun 27, 2008 at 05:26 UTC
    A simple example of Net::SSH::Expect..this simply connects
    through ssh then check the prompt then sends a command or input..
    my $ssh= Net::SSH::Expect->new( host => $host, password=> $password, user => $user, raw_pty =>1, log_file => $outputfile."\.raw" ); $ssh->login(); $ssh->send("sudo su"); if ($ssh->peek(1)=~/Password\:/ig){######check if Password prompt come +s up### $ssh->send("supassword"); } my $commandline=$ssh->eat($ssh->peek(1)); $commandline=~ s/Password\://g; #####remove string "Password:" $commandline=~ s/su|sudo su//g; #####remove string "su" or "sudo su" $commandline=~ s/^\s+|\s+$//g; ####remove trailing and leading whites +paces

    sorry for my regex..i know its bad..=p
    i hope the example helps

    P.S. please do not forget to use strict and warnings..=)