From: enigma on
Hi all,

I installed W32Perl lately and had to do some modifications in order to
make it run on windows (like define the $ENV and create a .ssh folder.

First problem i faced is that the program is hanging after it executes
the command. I know that it has already executed the command from:

mazendesktop: Sending command: ls
mazendesktop: Requesting service exec on channel 1.

If i redirect the output ls > mazen.txt everything works fine and the
program exits normally.

Now the weird problem that i'm currently facing is when i send multiple
commands to be executed on the remote machine. The program hangs at
different places each time I run it.. i couldn't find any pattern to
this. and the commands im using are very simple (ls, mkdir, whoami)

Any help would be greatly appreciated. If you need the small scripts
i'll post it

Thank you,

Mazen

From: J. Gleixner on
enigma wrote:

> Any help would be greatly appreciated. If you need the small scripts
> i'll post it

Of course that's needed, how else could anyone possibly determine the
issue with your code? You may try to 'debug' your code, on your own, to
help narrow down the issue. Also, there is a Net:SSH discussion group
where you may possibly find the solution or a similar issue that was
reported:
http://sourceforge.net/mailarchive/forum.php?forum=ssh-sftp-perl-users
From: enigma on
Here's my script:

use strict;
use Net::SSH::W32Perl;
my $host = 'antar';
my $user = 'oracle';
my $pwd = 'oracle';
$ENV{'HOME'} = '/temp';
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
$ssh-> login($user, $pwd);

$ssh-> cmd("ls > mazen1.txt","\n");
$ssh-> cmd("uname > mazen2.txt","\n");
$ssh-> cmd("uname > mazen3.txt","\n");
$ssh-> cmd("uname > mazen4.txt","\n");
$ssh-> cmd("mkdir foo","\n");

here's what i get at the screen:
mazendesktop: Reading configuration data /temp/.ssh/config
mazendesktop: Reading configuration data /etc/ssh_config
mazendesktop: Connecting to antar, port 22.
mazendesktop: Socket created, turning on blocking...
mazendesktop: Remote version string: SSH-1.99-OpenSSH_3.6.1p2

mazendesktop: Remote protocol version 1.99, remote software version
OpenSSH_3.6.1p2
mazendesktop: Net::SSH::Perl Version 1.30, protocol version 2.0.
mazendesktop: No compat match: OpenSSH_3.6.1p2.
mazendesktop: Connection established.
mazendesktop: Sent key-exchange init (KEXINIT), wait response.
mazendesktop: Algorithms, c->s: 3des-cbc hmac-sha1 none
mazendesktop: Algorithms, s->c: 3des-cbc hmac-sha1 none
mazendesktop: Entering Diffie-Hellman Group 1 key exchange.
mazendesktop: Sent DH public key, waiting for reply.
mazendesktop: Received host key, type 'ssh-dss'.
mazendesktop: Host 'antar' is known and matches the host key.
mazendesktop: Computing shared secret key.
mazendesktop: Verifying server signature.
mazendesktop: Waiting for NEWKEYS message.
mazendesktop: Enabling incoming encryption/MAC/compression.
mazendesktop: Send NEWKEYS, enable outgoing encryption/MAC/compression.
mazendesktop: Sending request for user-authentication service.
mazendesktop: Service accepted: ssh-userauth.
mazendesktop: Trying empty user-authentication request.
mazendesktop: Authentication methods that can continue:
publickey,password,keyboard-interactive.
mazendesktop: Next method to try is publickey.
mazendesktop: Next method to try is password.
mazendesktop: Trying password authentication.
mazendesktop: Login completed, opening dummy shell channel.
mazendesktop: channel 0: new [client-session]
mazendesktop: Requesting channel_open for channel 0.
mazendesktop: channel 0: open confirm rwindow 0 rmax 32768
mazendesktop: Got channel open confirmation, requesting shell.
mazendesktop: Requesting service shell on channel 0.
mazendesktop: channel 1: new [client-session]
mazendesktop: Requesting channel_open for channel 1.
mazendesktop: Entering interactive session.
mazendesktop: Sending command: ls > mazen1.txt
mazendesktop: Requesting service exec on channel 1.
mazendesktop: channel 1: send eof
mazendesktop: channel 1: open confirm rwindow 131071 rmax 32768
mazendesktop: input_channel_request: rtype exit-status reply 0
mazendesktop: channel 1: rcvd eof
mazendesktop: channel 1: output open -> drain
mazendesktop: channel 1: rcvd close
mazendesktop: channel 1: obuf empty
mazendesktop: channel 1: output drain -> closed
mazendesktop: channel 1: close_write
mazendesktop: channel 1: send close
mazendesktop: channel 1: full closed
mazendesktop: channel 2: new [client-session]
mazendesktop: Requesting channel_open for channel 2.
mazendesktop: Entering interactive session.
mazendesktop: Sending command: uname > mazen2.txt
mazendesktop: Requesting service exec on channel 2.
mazendesktop: channel 2: send eof
mazendesktop: channel 2: open confirm rwindow 131071 rmax 32768
mazendesktop: input_channel_request: rtype exit-status reply 0
mazendesktop: channel 2: rcvd eof
mazendesktop: channel 2: output open -> drain
mazendesktop: channel 2: rcvd close
mazendesktop: channel 2: obuf empty
mazendesktop: channel 2: output drain -> closed
mazendesktop: channel 2: close_write
mazendesktop: channel 2: send close
mazendesktop: channel 2: full closed
mazendesktop: channel 3: new [client-session]
mazendesktop: Requesting channel_open for channel 3.
mazendesktop: Entering interactive session.
mazendesktop: Sending command: uname > mazen3.txt
mazendesktop: Requesting service exec on channel 3.
mazendesktop: input_channel_request: rtype exit-status reply 0
mazendesktop: channel 3: rcvd eof
mazendesktop: channel 3: output open -> drain
mazendesktop: channel 3: rcvd close
mazendesktop: channel 3: input open -> closed
mazendesktop: channel 3: close_read
mazendesktop: channel 3: obuf empty
mazendesktop: channel 3: output drain -> closed
mazendesktop: channel 3: close_write
mazendesktop: channel 3: send close
mazendesktop: channel 3: full closed
---> Program hangs here

From: J. Gleixner on
enigma wrote:
> Here's my script:
>
> use strict;

Good!

> use Net::SSH::W32Perl;
> my $host = 'antar';
> my $user = 'oracle';
> my $pwd = 'XXXXXXXX';
Hopefully, that isn't your actual data.. Never post the actual user &
password.

> $ENV{'HOME'} = '/temp';
> my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
> $ssh-> login($user, $pwd);
>
> $ssh-> cmd("ls > mazen1.txt","\n");
> $ssh-> cmd("uname > mazen2.txt","\n");
> $ssh-> cmd("uname > mazen3.txt","\n");
> $ssh-> cmd("uname > mazen4.txt","\n");
> $ssh-> cmd("mkdir foo","\n");
[...]
> mazendesktop: Sending command: uname > mazen3.txt
[...]
> ---> Program hangs here
>

Why the "\n"??
Use full paths to your command.

Try wrapping everything in an eval, to see if it's dying for some reason.

$|++;
eval {
my $ssh = Net::SSH::W32Perl->new(
$host,
protocol => 2,
debug => 1 );
$ssh->login($user, $pwd);
#Use full paths to the command.
$ssh->cmd( '/bin/ls > mazen1.txt' ):
$ssh->cmd( '/bin/uname > mazen2.txt' );
$ssh->cmd( '/bin/uname > mazen3.txt' );
$ssh->cmd( '/bin/uname > mazen4.txt' );
$ssh->cmd( '/bin/mkdir foo' );
};
print "Error: $@\n" if $@;

Or possibly something more verbose...

$|++;
my $ssh = Net::SSH::W32Perl->new($host, protocol => 2, debug=>1);
$ssh->login($user, $pwd);
run_cmd( '/bin/ls > mazen1.txt' ):
run_cmd( '/bin/uname > mazen2.txt' );
etc..

sub run_cmd
{
my $cmd = shift;

my( $out, $err, $exit ) = $ssh->cmd( $cmd ):
print "cmd=$cmd out=$out err=$err exit=$exit\n";
}