09-29-2014 03:33 AM
Hello,
I want to catch the description field of this output:
#sh run | sec l2vpn xconnect context 11111
l2vpn xconnect context 11111
description BLAH BLAH
member GigabitEthernet0/7 service-instance 3501
member 50.50.0.34 11111 encapsulation mpls
so I wrote:
action 210 cli command "sh run | sec l2vpn xconnect context $vcid"
action 220 regexp "description "(.*)"" "$_cli_result" match desc
The regexp intercepts the whole output after the pattern "description ". I was not able to manage the \n \r etc special characters.
As a workaround I configure like this:
l2vpn xconnect context 11111
description "BLAH BLAH"
member GigabitEthernet0/7 service-instance 3501
member 50.50.0.34 11111 encapsulation mpls
And parse like this:
action 220 regexp "description "(.*)"" "$_cli_result" match desc
Any clues to instruct regexp in order to catch the end of the line ?
Regards
Andrea
09-29-2014 12:53 PM
Try:
regexp "description (.*)[[:space:]]+member" $_cli_result match descr
10-01-2014 03:55 AM
Hello Joseph,
Sorry for the late answer. I've read many of your suggestion on this subject.
Anyway I get a null string back.
I have a new challenge: I wanted to revert to the previous config and the device refuses...
XXXXX(config-applet)#action 220 regexp "description "(.*)"" "$_cli_result" match desc
^
% Invalid input detected at '^' marker.
Andrea
10-01-2014 05:27 AM
Well,
at the least the new challenge is done. If I type:
action 220 regexp "description \"(.*)\"" "$_cli_result" match desc
it works, and the config shown is:
action 220 regexp "description "(.*)"" "$_cli_result" match desc
Andrea
10-01-2014 12:45 PM
Hmmm, something didn't transfer right. My action was:
regexp "description (.+)[ [ :space : ] ]+member" $_cli_result match descr
Apparently, CSC eats the double brackets. I added spaces, but there should be no spaces between the brackets.
10-02-2014 01:18 AM
I have tried the regexp with the sequence of two open square brackets immediately followed by two closed square brackets and no space, but the result is (I believe) no match, bacause the variable desc remains stuck to the previusly deined value of "none".
On the other hand, interstingly, the result of:
action 170 regexp "description (.+)+member" $_cli_result match desc
gives a string (whatch carefully spaces and line feed):
"BLAH BLAH
member GigabitEthernet0/7 service-instance 3501
"
So it stops after the SECOND line, and ignores the last one... Quite strange.
Andrea
10-02-2014 10:38 AM
Did you include the colons? They are important. Pretend '|' stands for '['. It would look like:
||:space:]]
The word "space" and the colons are important.
10-02-2014 10:40 AM
The other way to do this is to iterate:
foreach line $_cli_result "\n"
regexp "description (.+)" $line match descr
if $_regexp_result eq 1
break
end
end
10-03-2014 05:17 AM
Joseph,
I reworked the config keeping in mind your hints and found (I believe)a good solution:
action 170 regexp "description (££:print:€€+)" "$_cli_result" match desc
££ stand for double [
€€ stand for double ]
Andrea
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide