Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Using Net::SSH2 with Net::Telnet::Cisco

by salva (Abbot)
on Apr 05, 2011 at 08:16 UTC ( #897455=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using Net::SSH2 with Net::Telnet::Cisco
in thread Using Net::SSH2 with Net::Telnet::Cisco

It seems that Net::Telnet prefers talking through a tty.

That works for me:

#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Net::Telnet; $Net::OpenSSH::debug = -1; my $ssh = Net::OpenSSH->new('localhost'); my ($fh, $pid) = $ssh->open2pty(); my $conn = Net::Telnet->new(Fhopen => $fh); my @lines = $conn->cmd("find /tmp"); print @lines; my @lines1 = $conn->cmd("ls"); print "\n\nls:\n", @lines1;

Replies are listed 'Best First'.
Re^4: Using Net::SSH2 with Net::Telnet::Cisco
by gnork (Scribe) on Aug 07, 2012 at 11:02 UTC
    Another late reply:

    I had to make a few adjustments to your code to get it to work properly on a Cisco device:

    use strict; use warnings; use Net::OpenSSH; use Net::Telnet; $Net::OpenSSH::debug = -1; my $promptEnd = '/\w+[\$\%\#\>]\s{0,1}$/o'; my $timeout = 60; my $ssh = Net::OpenSSH->new('your.ciscodevice.here', user => 'johndoe', password => 'secretpass', kill_ssh_on_timeout => 1, timeout => $timeout); # stderr_to_stdout was required to get Net::Telnets waitfor() to work my ($fh, $pid) = $ssh->open2pty({stderr_to_stdout => 1}); my %params = ( fhopen => $fh, prompt => $promptEnd, timeout => $timeout, errmode => 'return', telnetmode => 0, cmd_remove_mode => 1, output_record_separator => "\r", ); my $conn = Net::Telnet->new( %params ); my @lines = $conn->cmd("show tech"); print @lines;


    PS: Error checks removed, insert them at will.

    cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
    errors->(c)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://897455]
help
Chatterbox?
[Corion]: Meh. My bank removed (part of) their CSV download facilities. Now I will either have to implement a full scraper or automate the download using the HBCI interface instead (or just get a new account elsewhere...)
[Corion]: On the upside, I spend a lot of time thinking this weekend about how to actually implement rate limiting for futures, and if things work out, maybe even loading a configuration from an external file makes sense
[Corion]: I've also found some interesting invariants that I have to think/write about more. A simple rate limiter will never change the order of the input, while a limiter that allows for parallel execution will change the order. But my API currently allows for bo
[Corion]: ... for both, and I'm not sure if I want to add the cruft from the parallel API (a token that you need to hold on to while you hold the lock) to the rate limiting API too, to allow seamless up/downgrades, or not.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-10-23 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (277 votes). Check out past polls.

    Notices?