Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: accessing Cisco via SSH

by afresh1 (Hermit)
on Oct 12, 2010 at 21:23 UTC ( #864957=note: print w/replies, xml ) Need Help??


in reply to accessing Cisco via SSH

I would definitely start with use strict. In this case I don't know where you get the TRUE and FALSE constants because those don't normally exist in perl. This means that when $ssh = FALSE then if ($ssh) still evaluates to true.

As far as "Doesn't work with SSH devices", you weren't very clear on what doesn't work and what sort of errors you are getting from that so I am not sure how much I can help.

l8rZ,
--
andrew

Replies are listed 'Best First'.
Re^2: accessing Cisco via SSH
by Always Improving (Initiate) on Oct 13, 2010 at 00:51 UTC
    Thanks for that. I thought those were the T/F keywords in Perl, but I can figure that out I reckon. Unfortunately, the SSH part gives no errors at all. It prints out that it is connecting via SSH, but then nothing after that print actually happens. I *think* it is logging into the devices though, as if I spam 'sh users' on the switch, I can see the account log in and then quickly disappear. I also tried adding some sleep statements after each cmd, but to no avail. I also added print statements after every line in the SSH block to see if any of the statements were executing - I know, that is crude - and only the print before the snippet to snarf the hostname was successful.

    Thanks again

      In this line:
      my(@hostline, $stderr, $exit) = $cs->cmd('sh run | inc hostname');
      gives you all return values in @hostline and nothing in $stderr or $exit. If you are getting logged in, it should be able to run commands. Using print is a very valuable diagnostic tool. I would probably even go as far as making something very simple for testing.

      use strict; use warnings; use Net::SSH::Perl; $ENV{'HOME'} = 'c:\strawberry'; my $ip = 'xxx'; my $user = '********'; my $pw = '********'; # If you use single quotes, only single quotes +will to be escaped with '\' my $cs = Net::SSH::Perl->new($ip); if ($cs->login( $user, $pw)) { print $cs->cmd('sh run | inc hostname'); } else { warn "Unable to login\n"; } $cs->close;
      l8rZ,
      --
      andrew

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2023-03-31 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (74 votes). Check out past polls.

    Notices?