[Ssh-sftp-perl-users] Net::SSH::Perl with enterasys switches
Brought to you by:
dbrobins
|
From: Nicholas S. <pro...@ya...> - 2008-02-19 15:46:02
|
Hey everyone,
I am a Network Technician for Morrisville State College and Im attempting to use Net::SSH::Perl to SSH into all the switches we have on campus and retrieve some data from them. Unfortunately this isn't going my way. I have below my code and debug output.
Help with this would make my day,
Thanks,
Nicholas
Code:
#!/usr/bin/perl
use Net::SSH::Perl;
# get the addresses from the a file the user inputs
#ask the user where the file is
print "Please enter the path to the list of devices: ";
$filepath = <STDIN> ;
open(IPS, $filepath);
@addyarray = <IPS>;
close(IPS);
#ask the user what the username and password are
print "Please enter the username to login as: ";
$user = <STDIN> ;
chomp($user);
#ask the user what the password is
print "Please enter the password for " . $user . ":";
$pass = <STDIN> ;
chomp($pass);
#ask the user where the out file is
print "Please enter the filename you want the data to be placed in: ";
$outfile = <STDIN> ;
chomp($outfile);
#open the file to append data
open(OUT, ">>$outfile");
#below is a loop that gets the IP and connects to the device via SSH
foreach $address (@addyarray) # Visit each address in turn
# and call it address
{
print "currently working on device " . $address;
my $ssh = Net::SSH::Perl->new($address, debug => true);
$ssh->login($user, $pass);
my $cmd="show system";
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print OUT "-----------------------------------------------\n";
print OUT "Information for " . $address;
print OUT "-----------------------------------------------\n";
print OUT "output for command" . $cmd;
print OUT $stdout . "\n";
print OUT "errors for command" . $cmd;
print OUT $stderr . "\n";
print OUT "\n\n";
my $cmd="show ver";
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print OUT "---------------------\n";
print OUT "output for command" . $cmd;
print OUT $stdout . "\n";
print OUT "errors for command" . $cmd;
print OUT $stderr . "\n";
print OUT "\n\n\n";
}
#close the output file and save changes
close(OUT);
#tell the user when we are done
print "Information retrieval complete \n";
Debug info:
currently working on device 10.255.101.198
riley: Reading configuration data /home/nicholas/.ssh/config
riley: Reading configuration data /etc/ssh_config
riley: Connecting to 10.255.101.198
, port 22.
riley: Remote version string: SSH-2.0-FreSSH.0.8
riley: Remote protocol version 2.0, remote software version FreSSH.0.8
riley: Net::SSH::Perl Version 1.30, protocol version 2.0.
riley: No compat match: FreSSH.0.8.
riley: Connection established.
riley: Sent key-exchange init (KEXINIT), wait response.
riley: Algorithms, c->s: 3des-cbc hmac-sha1 none
riley: Algorithms, s->c: 3des-cbc hmac-sha1 none
riley: Entering Diffie-Hellman Group 1 key exchange.
riley: Sent DH public key, waiting for reply.
riley: Received host key, type 'ssh-dss'.
riley: Permanently added '10.255.101.198
' to the list of known hosts.
riley: Computing shared secret key.
riley: Verifying server signature.
riley: Waiting for NEWKEYS message.
riley: Enabling incoming encryption/MAC/compression.
riley: Send NEWKEYS, enable outgoing encryption/MAC/compression.
riley: Sending request for user-authentication service.
riley: Service accepted: ssh-userauth.
riley: Trying empty user-authentication request.
riley: Authentication methods that can continue: password.
riley: Next method to try is password.
riley: Trying password authentication.
riley: Login completed, opening dummy shell channel.
riley: channel 0: new [client-session]
riley: Requesting channel_open for channel 0.
riley: channel 0: open confirm rwindow 0 rmax 16384
riley: Got channel open confirmation, requesting shell.
riley: Requesting service shell on channel 0.
riley: channel 1: new [client-session]
riley: Requesting channel_open for channel 1.
riley: Entering interactive session.
riley: Channel open failure: 1: reason 1: unable to create channel
riley: channel 2: new [client-session]
riley: Requesting channel_open for channel 2.
riley: Entering interactive session.
riley: channel 0: rcvd close
riley: channel 0: output open -> drain
riley: channel 0: input open -> closed
riley: channel 0: close_read
Information retrieval complete
output to file:
-----------------------------------------------
Information for 10.255.101.198
-----------------------------------------------
output for commandshow system
errors for commandshow system
---------------------
output for commandshow ver
errors for commandshow ver
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|