Folks,

I installed NET::SSH2 on my windows box and wrote a little script that
connects to a cisco router and runs a command.  This works great, however
when I try to run a second command I get an error ->"return rc = -1".  The
first command still runs and produces the output but the second command
produces the error.  Is it possible to run more than one command?  If so,
anyone have a way to do it?

 

Code snippet:

#!C:\perl\bin\perl -w

  use strict;

  use Net::SSH2;

  use MIME::Base64;

 

  my $user="user1";

  my $pass="T#2&gsd9=";

   

  my $ssh2 = Net::SSH2->new();

  $ssh2->debug(1); 

  $ssh2->connect(1.2.3.4) or die "Unable to connect host $@ \n";

  my $dp=decode_base64("$pass");

  $ssh2->auth_password("$user","$dp");

  my $chan = $ssh2->channel();

  $chan->exec('sh ver');

  my $buflen = 30000;

  my $buf1 = '0' x $buflen;

  $chan->read($buf1, $buflen);

  print "BUF1:\n", $buf1,"\n";

 

  #try to run another command

  $chan->exec('sh int');

  my $buf2 = '0' x $buflen;

  $chan->read($buf2, $buflen);

  print "BUF2:\n", $buf2,"\n";

 

last few lines of output:

Net::SSH2::Channel::read(size = 30000, ext = 0)

return rc = -1

- read -1 bytes

BUF2:

 

Net::SSH2::Channel::DESTROY

Net::SSH2::DESTROY object 0x1996a4c

 

TIA,

David M. Funk
President/CEO
 
Tivoli Certified Enterprise Consultant
Specializing in Network and Systems Management Solutions

 

Trinity Solutions           
604 Cassandra Dr.        
Cranberry Twp., PA 16066
 
Phone: 724-316-0721                    
Fax:     724-772-7889 
email:  <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
www:    <http://www.trinityITsolutions.com>
http://www.trinityITsolutions.com

 

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to