Perl Regex problem

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.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|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;

Show the input you get and the output you want.

I'm not sure that code is actually doing what you want, either. I'm guessing you want to send 'show int' to the switch, and have Perl filter the rest? Or is the command you enter in the switch LITERALLY show int | i proto.* ... because that's what I think is happening here.

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

OK, that's the input you have. Now, show the output you want.

I'm not sure what the error you posted has to do with anything, is that a log entry or a perl error, and what do you want done with it?

How would I trim the results in my array from a result of a match? Would I do that before with a new array? Totally lost.

 
 foreach (@version_info) {
                 if ($_ =~ /(.*) is down, line protocol is down \(notconnect\)(.*)/) {
                         $session_obj->cmd('conf t');
                         $session_obj->cmd('int $_);
                         $session_obj->cmd('shutdown');
                         $session_obj->cmd('exit');
                 };
               };
 

Hi,

try like below:

#!/usr/bin/perl -w

my @a = ("hi", "hello", "GigabitEthernet1/0/3 is down, line protocol is down (notconnect)");

foreach (@a) {
if ( $_ =~ /(.*) is down,.*/) {
        print "$1\n";
}
}

In your case

$session_obj->cmd('int $1);
1 Like