Piece o' cake. What you want to do is use a local script to telnet to host1, then from that host telnet to host2, and capture command output, right?

Simply create a telnet object, establishing a connection to host1, print a telnet command to host2 via that object, then tell the object to login again, this time with host2's settings.

I tested this with Net::Telnet, but I suspect it would work with ::Cisco as well. You might also add code to logout gracefully.

#!/perl -w use strict; use Net::Telnet; # Cavaets: # # 1. This simple example assumes that the login, password, and command # prompts are all able to be matched by the Net::Telnet defaults - if # not, you'll need to add the appropriate parameters to the login() # command when logging in to host2. # # 2. I'm not sure $! is going to be meaningful in my die() statements, # but what the heck - insert your own debugging if it's not working. # :-) # First host my $host1 = 'hostname1'; my $user1 = 'user1'; my $pass1 = 'password1'; # Second host my $host2 = 'hostname2'; my $user2 = 'user2'; my $pass2 = 'password2'; my $session = new Net::Telnet (host => $host1) or die "Couldn't create: $!"; $session->login($user1, $pass1) or die "Couldn't login to $host1: $!"; $session->print("telnet $host2") or die "Couldn't telnet to $host2: $! +"; $session->login($user2, $pass2) or die "Couldn't login to $host2: $!"; # Obviously, put your own commands in here - $session is now talking # to host2 via host1. my @output = $session->cmd('uptime') or die "Couldn't run command: $!" +; print "@output"; exit;

In reply to Re: Using Net::Telnet::Cisco toTelnet from Host to Host by McD
in thread Using Net::Telnet::Cisco toTelnet from Host to Host by mdavis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.