Switches, Hubs, and Modems
1827815 Members
1739 Online
109969 Solutions
New Discussion

Script SSH Connection to Procurve Switches

 
SOLVED
Go to solution
tstella
New Member

Script SSH Connection to Procurve Switches

I'm having some trouble writing a Perl script to ssh into a procurve switch. It does have SSH enabled and I am able to manually connect via SSH. Here is the script, and the debug output:

---------------------------
Script
---------------------------

#!/bin/perl


use Net::SSH::Perl;

$host = "IP";
my $ssh = Net::SSH::Perl->new($host, protocol => 2, debug => 1, use_pty => 1);
$ssh->login("admin","passwordomitted");
$ssh->sock->print("\n");
sleep(2);
my ($stdout, $stderr) = $ssh->cmd("sh ver\n");
print "Output: $out\n";



-----------------------------
Debug Output
-----------------------------
debian: Reading configuration data /home/timothy/.ssh/config
debian: Reading configuration data /etc/ssh_config
debian: Connecting to ip, port 22.
debian: Remote protocol version 1.99, remote software version OpenSSH_3.4p1
debian: Net::SSH::Perl Version 1.34, protocol version 2.0.
debian: No compat match: OpenSSH_3.4p1.
debian: Connection established.
debian: Sent key-exchange init (KEXINIT), wait response.
debian: Algorithms, c->s: 3des-cbc hmac-sha1 none
debian: Algorithms, s->c: 3des-cbc hmac-sha1 none
debian: Entering Diffie-Hellman Group 1 key exchange.
debian: Sent DH public key, waiting for reply.
debian: Received host key, type 'ssh-rsa'.
debian: Host 'ip' is known and matches the host key.
debian: Computing shared secret key.
debian: Verifying server signature.
debian: Waiting for NEWKEYS message.
debian: Send NEWKEYS.
debian: Enabling encryption/MAC/compression.
debian: Sending request for user-authentication service.
debian: Service accepted: ssh-userauth.
debian: Trying empty user-authentication request.
debian: Authentication methods that can continue: password.
debian: Next method to try is password.
debian: Trying password authentication.
debian: Login completed, opening dummy shell channel.
debian: channel 0: new [client-session]
debian: Requesting channel_open for channel 0.
debian: channel 0: open confirm rwindow 0 rmax 32768
debian: Got channel open confirmation, requesting shell.
debian: Requesting service shell on channel 0.
debian: channel 1: new [client-session]
debian: Requesting channel_open for channel 1.



I am also open to writing the script in another language, as long as it will work.

Thanks,

Tim Stella
4 REPLIES 4
Mohammed Faiz
Honored Contributor

Re: Script SSH Connection to Procurve Switches

Hi,

That's about as far as I got using Net::SSH on a Windows host. There was no way of getting the session to complete and I couldn't find anyone else that had managed it.
Even passing commands directly using plink fails to work.
A colleague had it working using a horrible method of auto-pasting commands into an open putty window.
In the end I decided all we needed from the scripts was a copy of the configs so I use SCP to pull that down and we use PCM+ for anything that requires us to send batches of commands.
EckerA
Respected Contributor
Solution

Re: Script SSH Connection to Procurve Switches

hi,

i always use teraterm and ttmacro for scripts.
works like a charm..

hth
alex
tstella
New Member

Re: Script SSH Connection to Procurve Switches

Hi EckerA,

I've been looking into ttmacro/tera term. Looks pretty good. Would it be possible for you to post of one of your scripts? I seem to be having some problems getting mine to connect correctly.

Thank you,

Tim Stella
EckerA
Respected Contributor

Re: Script SSH Connection to Procurve Switches

Sure,

here is a place for a lot of informations and scripts for tterm and ttmacro:

http://logmett.com/forum/index.php

there u can as well find a script to connect via ssh.

for example:

connect 'xxxx.xxx.xxx.xx:22 /ssh /auth=password /user=net/passwd=xxxxx'

ShowRun = 'show run'

mpause 3000

sendln ShowRun#



hth
alex