Net::SSH::Perl - remoteinteract.pl doesn?t work

M

Martin Kissner

There´s an examplescript on http://search.cpan.org/src/DROLSKY/Net-SSH-
Perl-1.25/eg/remoteinteract.pl

It´s not working with me although I have
The "passwd" command gets send and the output of the Command on the
remote Computer is recieved by the script (which I have proofed by
adding additional debug-commands).
Then the script hangs.
This must be at theses lines of code:

--- snip ---
if ($str eq "(current) UNIX password: ") {
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($old_password);
$packet->send;
--- snap ---

Has anyone run the "remoteinteract.pl" successfully ?
Is there any other approach to run ssh-commands interactively?
 
A

A. Sinan Unur

There´s an examplescript on http://search.cpan.org/src/DROLSKY/Net-
SSH-Perl-1.25/eg/remoteinteract.pl

It´s not working with me although I have

Although what?
The "passwd" command gets send and the output of the Command on the
remote Computer is recieved by the script (which I have proofed by
adding additional debug-commands).
Then the script hangs.
This must be at theses lines of code:

--- snip ---
if ($str eq "(current) UNIX password: ") {
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($old_password);
$packet->send;
--- snap ---

Has anyone run the "remoteinteract.pl" successfully ?

Hint:

FreeBSD 5.2.1-RELEASE (RECEX) #1: Sun May 30 15:27:51 EDT 2004

xxx@recex:~ > passwd
Changing local password for xxx
Old Password:
 
M

Martin Kissner

* A. Sinan Unur said:
Although what?
.... although I have change the skript to fit my system´s (Mac OS X)
passwd-Command and have added values for the variables needed ($host,
$new_password etc.)

(Sorry, that i missed the line - I´m new to the Usenet and to slrn)
Hint:

FreeBSD 5.2.1-RELEASE (RECEX) #1: Sun May 30 15:27:51 EDT 2004

xxx@recex:~ > passwd
Changing local password for xxx
Old Password:
I have done it this way:

--- snip ---
....
if ($str =~ /password/) {
print "\n\tmatch 1\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($old_password);
$packet->send;
}
....
--- snap ---

I get "match 1" printed, the the skript hangs.
I suppose the $old_password soesn´t get send.

Any ideas ?
 
M

Martin Kissner

* A. Sinan Unur said:
Although what?
.... although I have change the skript to fit my system´s (Mac OS X)
passwd-Command and have added values for the variables needed ($host,
$new_password etc.)

(Sorry, that i missed the line - I´m new to the Usenet and to slrn)
Hint:

FreeBSD 5.2.1-RELEASE (RECEX) #1: Sun May 30 15:27:51 EDT 2004

xxx@recex:~ > passwd
Changing local password for xxx
Old Password:
I have done it this way:

--- snip ---
....
if ($str =~ /Old/) {
print "\n\tmatch 1\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($old_password);
$packet->send;
}
....
--- snap ---

I get "match 1" printed, the the skript hangs.
I suppose the $old_password soesn´t get send.

Any ideas ?
 
A

A. Sinan Unur

I have done it this way:

--- snip ---
...
if ($str =~ /Old/) {
print "\n\tmatch 1\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($old_password);
$packet->send;
}
...
--- snap ---

I get "match 1" printed, the the skript hangs.
I suppose the $old_password soesn´t get send.

My first suggestion is to stop posting so many almost identical messages
in such a short period of time.

I am not able to get the script to run on Win XP due to unrelated issues:

C:\Dload> remoteinteract.pl
AardvarkIV: Reading configuration data c:/Home/asu1/.ssh/config
AardvarkIV: Reading configuration data /etc/ssh_config
AardvarkIV: Connecting to xxx.xxx.xxx.xxx, port 22.
AardvarkIV: Remote protocol version 1.99, remote software version
OpenSSH_x.x.xpx FreeBSD-20030924
AardvarkIV: Net::SSH::perl Version 1.25, protocol version 1.5.
AardvarkIV: No compat match: OpenSSH_x.x.xpx FreeBSD-20030924.
Your vendor has not defined Fcntl macro F_SETFL, used at
C:/Perl/site/lib/Net/SSH/Perl.pm line 214.

Now, a natural question occurs to me: Did you run the script with debug
enabled (as it is in the version available on CPAN)?

my $ssh = Net::SSH::perl->new($host, debug => 1);

If you did, why don't provide that information?

Please read the posting guidelines to learn how you can help those whose
help you want.
 
M

Martin Kissner

* A. Sinan Unur said:
My first suggestion is to stop posting so many almost identical messages
in such a short period of time. O.k. - sorry for that.

Now, a natural question occurs to me: Did you run the script with debug
enabled (as it is in the version available on CPAN)?

If you did, why don't provide that information?
Here it is:
---
saturn:~/20_perl/ssh martin$ ./remoteinteract_voyager.pl
saturn.maki.dom: Reading configuration data ~/.ssh/config
saturn.maki.dom: Reading configuration data /etc/ssh_config
saturn.maki.dom: Connecting to voyager, port 22.
saturn.maki.dom: Remote protocol version 1.99, remote software version
OpenSSH_3.6.1p1+CAN-2004-0175
saturn.maki.dom: Net::SSH::perl Version 1.25, protocol version 1.5.
saturn.maki.dom: No compat match: OpenSSH_3.6.1p1+CAN-2004-0175.
saturn.maki.dom: Connection established.
saturn.maki.dom: Waiting for server public key.
saturn.maki.dom: Received server public key (768 bits) and host key
(1024 bits).
Argument "ssh-rsa" isn't numeric in numeric eq (==) at
/System/Library/Perl/5.8.1/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line
4.
saturn.maki.dom: Host 'voyager' is known and matches the host key.
saturn.maki.dom: Encryption type: DES3
saturn.maki.dom: Sent encrypted session key.
saturn.maki.dom: Received encryption confirmation.
saturn.maki.dom: RSA authentication failed: Can't load public key.
saturn.maki.dom: Doing challenge response authentication.
saturn.maki.dom: No challenge presented.
saturn.maki.dom: Trying password authentication.
saturn.maki.dom: Sending command: passwd
saturn.maki.dom: Entering interactive session.

match 1
---
If I should post the whole script (30 lines), please let me know
Please read the posting guidelines ...
O.k. - I now did.
 
A

A. Sinan Unur

* A. Sinan Unur wrote:
Here it is:
---
saturn:~/20_perl/ssh martin$ ./remoteinteract_voyager.pl
saturn.maki.dom: Reading configuration data ~/.ssh/config
saturn.maki.dom: Reading configuration data /etc/ssh_config
saturn.maki.dom: Connecting to voyager, port 22.
saturn.maki.dom: Remote protocol version 1.99, remote software version
OpenSSH_3.6.1p1+CAN-2004-0175
saturn.maki.dom: Net::SSH::perl Version 1.25, protocol version 1.5.
saturn.maki.dom: No compat match: OpenSSH_3.6.1p1+CAN-2004-0175.
saturn.maki.dom: Connection established.
saturn.maki.dom: Waiting for server public key.
saturn.maki.dom: Received server public key (768 bits) and host key
(1024 bits).
Argument "ssh-rsa" isn't numeric in numeric eq (==) at
/System/Library/Perl/5.8.1/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line
4.
saturn.maki.dom: Host 'voyager' is known and matches the host key.
saturn.maki.dom: Encryption type: DES3
saturn.maki.dom: Sent encrypted session key.
saturn.maki.dom: Received encryption confirmation.
saturn.maki.dom: RSA authentication failed: Can't load public key.
saturn.maki.dom: Doing challenge response authentication.
saturn.maki.dom: No challenge presented.
saturn.maki.dom: Trying password authentication.
saturn.maki.dom: Sending command: passwd
saturn.maki.dom: Entering interactive session.

match 1

I am assuming we are still talking about the snippet you posted earlier:

Question: Which one of the following lines causes the behavior you are
seeing?

I would either use the debugger or insert some good old fashioned print
statements after each of the lines above to check that.

I went ahead and installed everything involved on the FreeBSD system I have
access to and tested the remoteinteract.pl script on my shell account with
my hosting provider. The remote password was successfully changed.

Here is the script as I tested it:

asu1@xxx:~ > perl -v

This is perl, v5.8.5 built for i386-freebsd-64int

asu1@xxx:~ > cat remoteinteract.pl

#!/usr/bin/perl
use constant HOST => 'example.com';
use constant USER => 'dummy';
use constant NEWPASS => 'newpass';
use constant OLDPASS => 'oldpass';

use strict;
use warnings;

use Net::SSH::perl;
use Net::SSH::perl::Constants qw( :msg );

my $ssh = Net::SSH::perl->new(HOST, debug => 1);
$ssh->login(USER, OLDPASS);

$ssh->register_handler(SSH_SMSG_STDERR_DATA, sub {
my($ssh, $packet) = @_;
my $str = $packet->get_str;

if ($str =~ /^\(current\) UNIX password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(OLDPASS);
$packet->send;
}

elsif ($str =~ /^New password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}

elsif ($str =~ /^Retype new password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}
});


$ssh->cmd('passwd');

__END__

asu1@xxx:~ > perl remoteinteract.pl
xxx.xxx.xxx.xxx: Reading configuration data /home/asu1/.ssh/config
xxx.xxx.xxx.xxx: Reading configuration data /etc/ssh_config
xxx.xxx.xxx.xxx: Connecting to example.com, port 22.
xxx.xxx.xxx.xxx: Remote protocol version 1.99, remote software version
OpenSSH_3.1p1
xxx.xxx.xxx.xxx: Net::SSH::perl Version 1.23, protocol version 1.5.
xxx.xxx.xxx.xxx: No compat match: OpenSSH_3.1p1.
xxx.xxx.xxx.xxx: Connection established.
xxx.xxx.xxx.xxx: Waiting for server public key.
xxx.xxx.xxx.xxx: Received server public key (768 bits) and host key (1024
bits).
xxx.xxx.xxx.xxx: Host 'example.com' is known and matches the host key.
xxx.xxx.xxx.xxx: Encryption type: DES3
xxx.xxx.xxx.xxx: Sent encrypted session key.
xxx.xxx.xxx.xxx: Received encryption confirmation.
xxx.xxx.xxx.xxx: RSA authentication failed: Can't load public key.
xxx.xxx.xxx.xxx: Doing challenge response authentication.
xxx.xxx.xxx.xxx: No challenge presented.
xxx.xxx.xxx.xxx: Trying password authentication.
xxx.xxx.xxx.xxx: Sending command: passwd
xxx.xxx.xxx.xxx: Entering interactive session.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top