Net::SSH::Perl remoteinteract.pl Problem

J

jrt409

Hello
Im trying to get the example remoteinteract.pl script working on
Solaris 10. It seems as if the handlers are not actually picking up the
output of the passwd command. Any idea why?

Thanks in advance for any reply's.

When run with debug flags turned on i get....
hostname# ./ssh_passwd_changer.pl
hostname: Reading configuration data /root/.ssh/config
hostname: Reading configuration data /etc/ssh_config
hostname: Allocated local port 1023.
hostname: Connecting to desthost, port 22.
hostname: Remote protocol version 2.0, remote software version
Sun_SSH_1.0
hostname: Net::SSH::perl Version 1.29, protocol version 2.0.
hostname: No compat match: Sun_SSH_1.0.
hostname: Connection established.
hostname: Sent key-exchange init (KEXINIT), wait response.
hostname: Algorithms, c->s: 3des-cbc hmac-sha1 none
hostname: Algorithms, s->c: 3des-cbc hmac-sha1 none
hostname: Entering Diffie-Hellman Group 1 key exchange.
hostname: Sent DH public key, waiting for reply.
hostname: Received host key, type 'ssh-dss'.
hostname: Host 'desthost' is known and matches the host key.
hostname: Computing shared secret key.
hostname: Verifying server signature.
hostname: Waiting for NEWKEYS message.
hostname: Enabling incoming encryption/MAC/compression.
hostname: Send NEWKEYS, enable outgoing encryption/MAC/compression.
hostname: Sending request for user-authentication service.
hostname: Service accepted: ssh-userauth.
hostname: Trying empty user-authentication request.
hostname: Authentication methods that can continue: publickey,password.
hostname: Next method to try is publickey.
hostname: Next method to try is password.
hostname: Trying password authentication.
hostname: Login completed, opening dummy shell channel.
hostname: channel 0: new [client-session]
hostname: Requesting channel_open for channel 0.
hostname: channel 0: open confirm rwindow 0 rmax 16384
hostname: Got channel open confirmation, requesting shell.
hostname: Requesting service shell on channel 0.
hostname: channel 1: new [client-session]
hostname: Requesting channel_open for channel 1.
hostname: Entering interactive session.
hostname: Sending command: passwd root
hostname: Requesting service exec on channel 1.
hostname: channel 1: open confirm rwindow 0 rmax 16384
hostname: channel 1: rcvd eof
hostname: channel 1: output open -> drain
hostname: input_channel_request: rtype exit-status reply 0
hostname: channel 1: rcvd close
hostname: channel 1: input open -> closed
hostname: channel 1: close_read
hostname: channel 1: obuf empty
hostname: channel 1: output drain -> closed
hostname: channel 1: close_write
hostname: channel 1: send close
hostname: channel 1: full closed

Script...

#!/usr/local/bin/perl -w

my($host, $username, $new_password, $old_password);

$host="<host>";
$username="root";
$new_password="<passwd>";
$old_password="<passwd>";

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

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

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

if ($str eq "New Password: ") {
print "first match\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($new_password);
$packet->send;
}

elsif ($str eq "Re-enter new password: ") {
print "second match\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str($new_password);
$packet->send;
}

});

$ssh->cmd("passwd root");
 
J

J. Gleixner

Hello
Im trying to get the example remoteinteract.pl script working on
Solaris 10. It seems as if the handlers are not actually picking up the
output of the passwd command. Any idea why?

Maybe you want to take a look at what output it is "picking up".
 
J

jrt409

Hi,
From my very limited understanding of the module, it appears that each
handler should send packets or some kinda response as stdin when its
picks up a predefined string from stderr/stdout. Ive checked and double
checked the output from the "passwd root" command on Solaris and its
matches exactly to what i have defined in the script. Ive also adjusted
the script to pickup stdout as opposed to stderr with no luck. Any help
would be much appreciated.
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top