First, please do yourself a favor and use strict;

This shouldn't work as expected since $ip is not expanded (remove the quotes): $t =Net::Telnet::Cisco->new(Host=>$ip);

When you try to connect/telnet to 192.168.201.3 and the error message is port:23 not connected, that's not a Perl problem, but a network connectivity problem (no telnet-daemon, wrong IP, firewalls, etc.).

The $k-session is totally useless, since you try to connect (again = 2nd parallel connection) to the private host from your local host, but not from the Cisco device. This explains the error described in the previous paragraph.

use Net::Cisco; use Net::Telnet(); # consider: use strict; $t =Net::Telnet::Cisco->new(Host=>'$ip'); # doesn't work: '$ip' -> $i +p (BTW: where is $ip defined?) print "connected"; # a bold statement w/o any +test (e.g. checking $t) $t->login('', ''); $t->cmd("telnet 192.168.201.3"); # failure? success? no chec +k here $k=Net::Telnet->new(Timeout=>10,Errmode=>'die'); # You are opening a second +session from localhost! # Try to do the $k-stuff fr +om within the $t-session. $k->open("192.168.201.3")or die "$k->errmsg"; print "connected"; # see above $k->waitfor('password:$/i'); $k->print("public"); $k->waitfor('>$/i'); @output=$k->print("show system"); open(CONFIG,">config.txt"); # three argument open + che +ck would be nice print CONFIG "@output\n"; close(CONFIG); $k->close; $t->close;

BTW: You can edit your nodes, e.g Reaped: telnet from a cisco telnet and do not need to create a new one when you want to update formatting or content.


In reply to Re: telnet from a cisco telnet by Perlbotics
in thread telnet from a cisco telnet by Kumar Mantri

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.