[Ssh-sftp-perl-users] Can't figure out how Net::ssh2 shell() method works.
Brought to you by:
dbrobins
|
From: <smi...@em...> - 2006-03-15 00:47:16
|
I'm trying to use Net::ssh2 to connect to a Cisco router. When I run the
script below, I get:
krypton:test$ ./test.pl
KEX = diffie-hellman-group1-sha1
HOSTKEY = ssh-rsa
CRYPT_CS = aes256-cbc
CRYPT_SC = aes256-cbc
MAC_CS = hmac-sha1
MAC_SC = hmac-sha1
COMP_CS = none
COMP_SC = none
auth_list ==> password
auth_ok ==> 4
in _read()
So, it looks like I'm getting connected and authenticated, but then there's
nothing to read from the channel. If I connect to the router with the
command-line ssh, I get:
krypton:test$ ssh cisco@10.9.6.250
cisco@10.9.6.250's password:
Center of the galaxy
qa>
What I was expecting when I called _read() was that I would get back the
"Center of the galaxy" banner, and the
"qa>" prompt. Instead I get nothing. What am I doing wrong?
----------------------------------------------
#!/usr/bin/env perl
use Net::SSH2;
use diagnostics;
my $ssh2 = Net::SSH2->new();
$ssh2->connect('10.9.6.250');
for $method ('KEX',
'HOSTKEY',
'CRYPT_CS',
'CRYPT_SC',
'MAC_CS',
'MAC_SC',
'COMP_CS',
'COMP_SC') {
$value = $ssh2->method($method);
print "$method = $value\n";
}
print "\n";
$alist = $ssh2->auth_list();
print "auth_list ==> $alist\n";
our $err = $ssh2->auth_password('cisco', 'XXXXX');
print "auth_ok ==> ", $ssh2->auth_ok(), "\n";
$chan = $ssh2->channel() or die "channel() failed";
$chan->pty("ansi") or die "pty() failed";
$chan->shell() or die "shell() failed";
_read ($chan);
sub _read {
print "in _read()\n";
my $handle = shift;
while (my $line = <$handle>) {
chomp $line;
$line =~ s/:.*$//;
print "found user '$line'\n";
}
}
Roy Smith <smi...@em...>
Staff SW Engineer
EMC / Smarts
+1 914 580 3427
|