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

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

Folks-

Given machine A, B, and C...

I'm trying to login from A to B and remotely execute an interactive command on C.

A is running a perl script that uses Net::SSH:Perl to machine B. This works fine for both SSH1 and SSH2.

Then A tries to run ssh -t -l $usr2 $machineC icommand" from machine B

This will work for SSH1, but will fail for SSH2 failing with:
ERR: Pseudo-terminal will not be allocated because stdin is not a terminal.

Machine A has been both a Sun and MacOS, and I see the same failure. My research indicates that Net::SSH::Perl is failing to setup the tty on machine B. Although I'm running an older version of Net::SSH::Perl, I don't see any code in the new version to fix this either.

Test code is attached - using "uname-a" instead of an interactive command, and ssh -t to force the error.

Any thoughts on how I can get this to work with SSH2?

Thanks

-Craig

UPDATE: I was able to modify SSH2.pm to fix this problem. A bug report has been submitted along with my code hacks to SSH2.pm that make it work.

use strict; use warnings; use Net::SSH::Perl; use Net::SSH::Perl::Constants qw( :msg ); my $host1='machineB'; my $usr1='usrB'; my $pass1='passwdB'; my $host2 = 'machineC'; my $usr2 = 'usrC'; my $cmd = "/opt/exp/bin/ssh -t -l $usr2 $host2 uname -a"; my $debug=0; my $ssh1 = Net::SSH::Perl->new($host1, use_pty=>1, protocol=>1, interactive=>1, debug=>$debug) || die "Cannot conntact target machine, exiting..."; $ssh1->login($usr1, $pass1) || die "Bad login, exiting..."; print STDERR "\n\nUsing SSH1 Protocol\n"; my ($out, $err, $exit) = $ssh1->cmd($cmd); print STDERR "exit=$exit\n"; print STDERR "OUT: $out\n" if $out; print STDERR "ERR: $err\n" if $err; # Using SSH2... # Adding use_pty=>1 does not work when using SSH2. See: # http://www.derkeiler.com/Newsgroups/comp.security.ssh/2003-05/0097.h +tml my $ssh2 = Net::SSH::Perl->new($host1, protocol=>2, use_pty=>1, interactive=>1, debug=>$debug) || die "Cannot conntact target machine, exiting..."; $ssh2->login($usr1, $pass1, 0) || die "Bad login, exiting..."; print STDERR "\n\nUsing SSH2 Protocol\n"; ($out, $err, $exit) = $ssh2->cmd($cmd); print STDERR "exit=$exit\n"; print STDERR "OUT: $out\n" if $out; print STDERR "ERR: $err\n" if $err;