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 | |
by Kumar Mantri (Novice) on Aug 09, 2011 at 09:11 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |