Re: [Ssh-sftp-perl-users] Device does not support shell request notpreceded by pty request
Brought to you by:
dbrobins
|
From: Heinrich, M. <Mat...@sa...> - 2006-11-27 22:52:21
|
I have been working on the same sort of problem for a while now. I was
getting this same error because the "cmd" function of Net::SSH::Perl
will always expect an exit code, and the devices to which we are
communicating do not support exit codes after each command. Also, the
device prefers to have all commands sent through the same channel, and
Net::SSH::Perl will open a new channel for each command when using
SSHv2.
At first, I tried copying "sub cmd" to "sub ccmd" and making it use the
same channel, but I could not get the buffers to work properly. A lot
of people said to use an Expect script, but that didn't seem like good
idea, until I took a look at the Expect Perl module...
I created a connecting script (connect.pl) which will login and get me
to an interactive prompt:
------------------------------------------------------------------------
--------
#!/usr/bin/perl
use strict;
use Net::SSH::Perl;
my $host =3D "a.b.c.d";
my $user =3D "uname";
my $pass =3D "pword";
my $ssh =3D Net::SSH::Perl->new($host, port=3D>22);
$ssh->login($user, $pass);
$ssh->shell();
------------------------------------------------------------------------
--------
Next, I created the main Perl script using the Expect module, spawning
this connection program:
------------------------------------------------------------------------
--------
#!/usr/bin/perl
use Expect;
$| =3D 1; # Auto flush output
my $exp =3D Expect->new();
# Prevent local echo from showing in results
$exp->raw_pty(1);
# Run connector program
$exp->spawn("./connect.pl");
# Prevent output from going to STDOUT
(*$exp)->{exp_Log_Stdout} =3D 0;
# Wait for initial prompt (30 sec timeout)
$exp->expect(30, "centerpoint>");
# Send command with no output needed
snd("set rows 0");
print "Sending remote command...";
# Send command, store output in @res array
@res =3D snd("show vss");
print "OK\n\nResults:\n";
# List output line-by-line
foreach $n (0..$#res) {
print "$n: @res[$n]\n";
}
$exp->send("exit\n");
$exp->soft_close();
# This makes sending multiple commands much easier. Instead of
# using multiple "send" and "expect" calls manually, just use snd
sub snd ($){
$exp->send(@_[0] . "\n");
# Use the "-re" option to specify regular expression, as
# opposed to an exact pattern match. Otherwise, you can=20
# just list 2 arguments (timeout, pattern match)
my @out =3D $exp->expect(10, "-re", 'centerpoint>$');
my @newout =3D split(/\n/, @out[3]);
# Remove first line (in my case, it shows the command I typed,
# which is not needed in the resulting output)
shift @newout;
return wantarray ? @newout : 1;
}
------------------------------------------------------------------------
--------
This script will wait for connect.pl to present the CLI prompt (in this
case, it shows "centerpoint>"), and will be able to interact with the
SSH session more easily than if you modified Net::SSH::Perl, or if you
used TCL Expect.
-----Original Message-----
From: ssh...@li...
[mailto:ssh...@li...] On Behalf Of
DonKiShoot
Sent: Wednesday, November 22, 2006 8:16 AM
To: ssh...@li...
Subject: Re: [Ssh-sftp-perl-users] Device does not support shell request
notpreceded by pty request
Hello all,
I'm trying to send some commands to my switch HP Procurve 2650 in ssh2
with Net::SSH::Perl with user 'operator' and pubkey authentification.
It appears that i have a problem when starting to send command but
authentification seems good.
This is sample of my perl script and next debug trace with error i
receive:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
foreach my $addr (keys %Switch) {
# print "$addr, $Switch{$addr}{'login'} :\n";
my $ssh =3D Net::SSH::Perl->new($addr,'debug' =3D> 1, 'use_pty' =3D> =
1,
'protocol' =3D> 2, 'interactive' =3D> 0, options =3D> =
["RhostsAuthentication
no"]);
#$ssh->register_handler("stdout", sub {
# my($channel, $buffer) =3D @_;
# print "I received this: ", $buffer->bytes;
# });
$ssh->login($Switch{$addr}{'login'});
my($stdout, $stderr, $exit) =3D $ssh->cmd("\n");
print "$stdout $stderr $exit\n";
($stdout, $stderr, $exit) =3D $ssh->cmd("ping $ip");
print "$stdout $stderr $exit\n";
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
srv78supervision: Reading configuration data /root/.ssh/config
srv78supervision: Reading configuration data /etc/ssh_config
srv78supervision: Allocated local port 1023.
srv78supervision: Connecting to 10.1.2.22, port 22.
srv78supervision: Remote version string: SSH-2.0-OpenSSH_3.7.1p2
srv78supervision: Remote protocol version 2.0, remote software version
OpenSSH_3.7.1p2
srv78supervision: Net::SSH::Perl Version 1.30, protocol version 2.0.
srv78supervision: No compat match: OpenSSH_3.7.1p2.
srv78supervision: Connection established.
srv78supervision: Sent key-exchange init (KEXINIT), wait response.
srv78supervision: Algorithms, c->s: 3des-cbc hmac-sha1 none
srv78supervision: Algorithms, s->c: 3des-cbc hmac-sha1 none
srv78supervision: Entering Diffie-Hellman Group 1 key exchange.
srv78supervision: Sent DH public key, waiting for reply.
srv78supervision: Received host key, type 'ssh-rsa'.
srv78supervision: Host '10.1.2.22' is known and matches the host key.
srv78supervision: Computing shared secret key.
srv78supervision: Verifying server signature.
srv78supervision: Waiting for NEWKEYS message.
srv78supervision: Enabling incoming encryption/MAC/compression.
srv78supervision: Send NEWKEYS, enable outgoing
encryption/MAC/compression.
srv78supervision: Sending request for user-authentication service.
srv78supervision: Service accepted: ssh-userauth.
srv78supervision: Trying empty user-authentication request.
srv78supervision: Authentication methods that can continue:=20
publickey,password.
srv78supervision: Next method to try is publickey.
srv78supervision: Trying pubkey authentication with key file
'/root/.ssh/id_dsa'
srv78supervision: Login completed, opening dummy shell channel.
srv78supervision: channel 0: new [client-session]
srv78supervision: Requesting channel_open for channel 0.
srv78supervision: channel 0: open confirm rwindow 0 rmax 32768
srv78supervision: Got channel open confirmation, requesting shell.
srv78supervision: Requesting service shell on channel 0.
srv78supervision: channel 1: new [client-session]
srv78supervision: Requesting channel_open for channel 1.
srv78supervision: Entering interactive session.
/*Received disconnect message: Device does not support shell request not
preceded by pty request.
at /usr/lib/perl5/vendor_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 284*/
What can i do to resolve this problem ?
Thx all
------------------------------------------------------------------------
-
Take Surveys. Earn Cash. Influence the Future of IT Join
SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D=
DEVDE
V
_______________________________________________
Ssh-sftp-perl-users mailing list
Ssh...@li...
https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users
|