http://qs321.pair.com?node_id=1048166

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

having an issue with sorting and dumping files out of a router. Here is what i got..looking to sort interfaces that are DOWN/UP.
#! /usr/bin/env/ perl -w use strict; use warnings; use Net::Telnet::Cisco; { use Data::Dumper; print( Dumper); } my $ip_address =""; my $username = ""; my $password = ""; my $prompt = '/.*[#\$%>]\s*$/'; my $session = Net::Telnet::Cisco->new(Host => $ip_address, Prompt => $ +prompt, Timeout =>20); $session->login($username, $password); # Execute a Command my @show_log_output = $session->cmd('show log'); my $mystring; $mystring = "up"; $mystring = "down"; print "$mystring"; print "@show_log_output\n"; #Execute a Command my @show_interface_desc_output = $session->cmd('show interface desc'); print "@show_interface_desc_output\n"; $session->close; exit;
<code>

Replies are listed 'Best First'.
Re: data dump and sort
by Illuminatus (Curate) on Aug 06, 2013 at 20:20 UTC
    1. Obviously, your use of the code-tag didn't work. Didn't the preview show you that?
    2. Since most of us don't have access to a Cisco router, it would be best if you included the output that you're getting vs what you're expecting
    3. Are you really asking 'how do I sort this?' It doesn't look like your code tries to sort anything

    fnord

Re: data dump and sort
by 5mi11er (Deacon) on Aug 07, 2013 at 01:57 UTC
    Worse, the code, once one puts line feeds in the appropriate spots, becomes apparent that it doesn't really DO anything.

    It does manage to get the output of two cisco commands (show log, and show interface description), then simply throws that info to the screen.

    If you're looking to see what interfaces are up/down, perhaps a "show ip int brief" (or similar command depending on the device and IOS version) might be more helpful?

    But it looks like you might be attempting to grasp at asking how to filter through the log file, looking for up/down messages. I would suggest reading up on regular expressions and the grep command, or you could do it line by line like this:

    while(@show_log_output) { if (/(up|down)/i) { print $_; } }
    -Scott
Re: data dump and sort
by 2teez (Vicar) on Aug 07, 2013 at 03:54 UTC

    Hi perldumbfounded12,

    • Your "code" tag is missing it's second pair. It should be <code> which you have and </code> which you are missing out.
    • having an issue with sorting and dumping files out of a router. Here is what i got..looking to sort interfaces that are DOWN/UP

      What follows is your script not the what you wanted to "sort" out.
      So, since you are new around here I suppose you may look into How do I post a question effectively?
    Welcome to the Monastery.

    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