Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Perl Regex

by lrobindon (Initiate)
on Nov 14, 2016 at 13:57 UTC ( [id://1175881]=perlquestion: print w/replies, xml ) Need Help??

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

I come seeking wisdom. Script logs into switches on my list but nothing seems to happen. Following error:
[ 5.546199] tr nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ + ?(?:\(config[^)]*\))? ?[#>] ?$) [ 5.550072] du SEEN:
Here is code in question:
@version_info = $session_obj->cmd('term length 0'); $session_obj->cmd('show int | i proto.*notconnect|proto.*admin +istratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disable +d|Last input never, output never, output hang never'); $session_obj->cmd('conf t'); foreach (@version_info) { if ($_ =~ /(.*) is down/) { $_ = $1; print $_; #$session_obj->cmd('conf t'); $session_obj->cmd("int $_"); $session_obj->cmd('shutdown'); } } $session_obj->cmd('exit'); $session_obj->close;

Replies are listed 'Best First'.
Re: Perl Regex
by Corion (Patriarch) on Nov 14, 2016 at 14:38 UTC

    There are some things that will help us give you a better answer. Most of all, what module you are using. Most likely, this would be something like Net::Telnet, and second, what the raw input data from the remote session looks like. For Net::Telnet, you would be able to obtain this input by using its debugging facilities.

    Most likely, you are fighting the prompt of your remote terminal respectively how to match the remote prompt of your terminal with the regular expression in the configuration of the module. But without seeing the remote prompt and the regular expression you're using, it's hard to diagnose where it goes wrong.

      I think I know the issue. The show command shows all ports that match the criteria. GigabitEthernet1/0/3 is down, line protocol is down (notconnect) Last input never, output never, output hang never Last input 17w0d, output 00:00:00, output hang never Last input 38w0d, output 00:00:00, output hang never Last input 48w5d, output 00:00:00, output hang never Last input 1y27w, output 00:00:00, output hang never GigabitEthernet1/0/18 is down, line protocol is down (notconnect) Last input never, output 6w6d, output hang never Those results go into a array. I can not figure out how to trim the array results to say, GigabitEthernet1/0/3 Linux
Re: Perl Regex
by AnomalousMonk (Archbishop) on Nov 14, 2016 at 14:34 UTC
Re: Perl Regex
by neilwatson (Priest) on Nov 14, 2016 at 14:34 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found