in reply to telnet from a cisco telnet

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.

Replies are listed 'Best First'.
Re^2: telnet from a cisco telnet
by Kumar Mantri (Novice) on Aug 09, 2011 at 09:07 UTC
    i modified this wrt your suggestions,...how about this
    use strict; use Net::Cisco; use Net::Telnet(); $t =Net::Telnet::Cisco->new(Host=>'192.168.1.1'); print "connected"; $t->login('9190', 'KUM@R425'); $t->cmd("telnet 192.168.201.3"); print "connected"; $t->waitfor('password:$/i'); $t->print("public"); $t->waitfor('>$/i'); @output=$t->print("show system"); open(CONFIG,">config.txt"); print CONFIG "@output\n"; close(CONFIG); $t->close;
      i ran the above script but it is showing the following error..
      Possible unintended interpolation of @output in string at C:\Users\Kum +ar\telnet. pl line 14. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 4. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 6. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 7. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 9. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 10. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 11. Global symbol "@output" requires explicit package name at C:\Users\Kum +ar\telnet. pl line 12. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 12. Global symbol "@output" requires explicit package name at C:\Users\Kum +ar\telnet. pl line 14. Global symbol "$t" requires explicit package name at C:\Users\Kumar\te +lnet.pl li ne 16.
A reply falls below the community's threshold of quality. You may see it by logging in.