Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Where is my Net::Telnet output

by CuriousBee (Initiate)
on Jul 05, 2011 at 11:51 UTC ( [id://912808]=perlquestion: print w/replies, xml ) Need Help??

CuriousBee has asked for the wisdom of the Perl Monks concerning the following question:

Hi, This is my first Perl Script. I am trying to telnet to a cisco router and get the output from a command. I am running my script from a Windows XP machine from the command prompt. I do not see the router output of the show command in the inputlog file. Please help. My script is as follows.
#!C/Perl -w use strict; use warnings; use Net::Telnet; my $telnet = new Net::Telnet ( Timeout=>10, Binmode=> 1, telnetmode => + 0, Input_log=>"input.log", Dump_log=>"dump.log", Output_log=>"output +.log", Errmode=>'die', Prompt=>'/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))? +\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print "I am opening a connection\n"; $telnet->open('x.y.z.x'); print "i established a connection\n"; $telnet->waitfor('/Username: $/i'); $telnet->print('xxx'); print "i entered username\n"; $telnet->waitfor('/Password: $/i'); $telnet->print('yyy'); print "i entered password\n"; $telnet->waitfor('/.*$/i'); print $telnet->cmd('show platform'); print 'I am done executing the show command'; $telnet->close();
The input.log file does show me that it has connected to the router prompt and dump_log does have these lines at the end. > 0x00000: 73 68 6f 77 20 70 6c 61 74 66 6f 72 6d 0a show platform. < 0x00000: 0d 0a 56 50 4e 76 34 2d 31 6b 2d 52 52 30 33 23 ..VPNv4-1k-RR03# But i dont see the output of the command "show platform" anywhere.. Please help. TIA.

Replies are listed 'Best First'.
Re: Where is my Net::Telnet output
by jettero (Monsignor) on Jul 05, 2011 at 11:59 UTC
    IOS is annoying to interact with via scripts. Have fun. I highly recommend Net::Telnet::Cisco. It helps quite a lot with some of the more annoying things.
      thanks for the reply. I just tried with Net::Telnet::Cisco and it works. However there 9k boxes that we have have a prompt of "RP/0/RSP0/CPU0:9K-PO1". For such a prompt my connection is not working. Do you know if there is a fix that I can use for this to work. TIA
        Hi, The regexp that is evaluating the prompt doesn't include the characters ":" and "/" that are present in your router names. So you have to alter the regexp used for the prompt. If you create the Net::Telnet::Cisco object "$obj" you can see what regexp is used with   print $obj->prompt, "\n"; And alter it with   $obj->prompt('/(?m:^[\w.:\/-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); The regexp I used above includes your special characters. So that should work.
Re: Where is my Net::Telnet output
by decnartne (Beadle) on Jul 05, 2011 at 18:49 UTC
    Also, the 'show platform' cmd requires an argument, e.g.:
    #show platform ? acl Display CWAN ACL commands bridge Distributed/Hardware-based bridging information buffers Show buffer allocation cfm Show CFM Commands eeprom Show CPU eeprom etherchannel Platform EtherChannel information fault Show fault data hardware Show platform hardware information internal-vlan Show internal vlan netint Show platform net interrupt information redundancy Display CWAN redundancy software Show platform software information stats Display CWAN statistics supervisor Show supervisor info tech-support Show system information for Tech-Support tlb Show processor TLB registers vfi Display CWAN VFI commands vlans Display hidden VLAN to WAN interface mapping

    decnartne ~ entranced

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://912808]
Approved by Corion
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2025-04-29 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.