Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Array not storing the result of a router command

by Arun Kumar (Novice)
on May 09, 2013 at 17:45 UTC ( #1032805=perlquestion: print w/ replies, xml ) Need Help??
Arun Kumar has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am trying to telnet to a cisco router and try to backup its configuration. The code which I wrote works for all the devices except a single device. But the commands are working fine when I run them manually in the router. I have gone through the code many times and I could not find what is going wrong. My @array which I use to get the command results is returning null value. Please help ASAP as its a bit urgent.

my $cs = Net::Telnet::Cisco->new (Host =>host,Errmode=> "return"); $cs->input_log ("/var/log/routers/cisco.$host.backup.input.log"); if ($type == 0) { $cs->login ("$user","$pw"); } my @cmd_output; if ($type == 0) { $cs->cmd ('terminal length 0'); @cmd_output = $cs->cmd ('show running-config'); print "Array value__________________'@cmd_output'\n"; ###Here t +he value comes as NULL }

Comment on Array not storing the result of a router command
Download Code
Re: Array not storing the result of a router command
by blue_cowdawg (Monsignor) on May 09, 2013 at 17:48 UTC

    Have you verified that you are successfully logging in? Seems to me you are not checking.

    Of course the other thought I have is what is different about this device?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      I have verified that I am logging in successfully into the device. The log function of the telnet session is writing all the command output to the session log file. Only the thing is that the array returns null value for this device alone.

      Not sure what is different, its one of the CISCO routers in my network. Rest routers data are visible in the array. but not this specific.

            Not sure what is different, its one of the CISCO routers in my network. Rest routers data are visible in the array. but not this specific.

        That's the nut you need to crack. If I have a script that runs in 9 cases out of 10 I want to see what is different about that tenth case.


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Array not storing the result of a router command
by 2teez (Priest) on May 09, 2013 at 18:56 UTC

    Hi Arun Kumar,
    Just Curious questions:

    1. Why test for the variable $type twice in your script?
    2. for this particular router, can you test another command to see if @cmd_output would not return null? like say:
      my @output = $session->cmd('show version'); print @output;
    3. In your print line, i.e print "Array value__________________'@cmd_output'\n"; why put the variable @cmd_output in a single quote? Does other router output give output in that like?
    Just thinking aloud....

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      Hi 2teez, Sorry for that, it is because I have four types of routers. I will first login into the routers at the first type check and then I will execute the different commands for different again by checking the router type. But I have shortened the code here.

      I have tried the show version command,it is also not getting stored into the array

Re: Array not storing the result of a router command
by topher (Scribe) on May 10, 2013 at 05:59 UTC

    This honestly sounds less like a problem with Perl and more likely a problem with the router. If I were you, I'd fire up wireshark (or more likely tshark) and grab a packet capture of your failing config capture session. Then take a look at it wireshark and see what's going on. Is the command being sent properly? Is the router returning the data you expect? One advantage of telnet is that it's all clear on the wire, so it's easy to troubleshoot.

    Speaking of that, you should really kill telnet and use ssh. This is a pretty basic security best practice. ;-)

    Christopher Cashell

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-09-23 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls