- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2021 05:31 AM
Hi All,
Looking for someone that can help me figure this one out
I want to parse the output of the sh run int t0 command, i need to match 2 things in the output, one is the ip address of the tunnel destination and the other is the tunnel source interface name
I cant find a way to do this in one loop, the only way it works for me is by going through the loop 2 times , once for each line..
this is the tunnel 0 config i am parsing:
interface Tunnel0
ip address negotiated
ip tcp adjust-mss 1350
tunnel source GigabitEthernet0/1
tunnel destination 1.2.3.4
this is the eem applet that works but ..yeah..its stupid as i am basically creating the same twice to get the result i need so lots of excess lines to do this simple thing:
conf t
event manager applet test
event none
action 0001 cli command "enable"
action 0002 cli command "sh run int t0"
action 0003 foreach line "$_cli_result" "\n"
action 0004 set OUT "$line"
action 0005 regexp "(source)\s(.*)" "$OUT" match sub1 sub2
action 0006 if $_regexp_result eq 1
action 0007 puts nonewline "$sub2"
action 0008 end
action 0009 end
action 0011 cli command "enable"
action 0012 cli command "sh run int t0"
action 0013 foreach line "$_cli_result" "\n"
action 0014 set OUT "$line"
action 0015 regexp "(destination)\s([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$OUT" match sub1 sub2
action 0016 if $_regexp_result eq 1
action 0017 puts nonewline "$sub2"
action 0018 end
action 0019 end
action 0020 exit
end
event manager run test
R1#event manager run test
FastEthernet0/0
1.2.3.4
So yeah it works, but i would like to shorten this if at all possible, now it requires almost 20 lines to accomplish it
Solved! Go to Solution.
- Labels:
-
Network Management
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2021 08:45 AM
Another option using 4 lines.
event manager applet tunnel event none action 010 cli command "enable" action 020 cli command "show run interface tunnel2" action 030 regexp "tunnel source ([a-zA-Z0-9\/]+).*tunnel destination ([0-9\.]+)" "$_cli_result" match intf ip action 040 puts "$intf $ip" ! C1111#event manager run tunnel GigabitEthernet0/0/1 10.64.1.202 C1111#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2021 05:50 AM
ok so i found one way to make it a little shorter:
event manager applet test
event none
action 0001 cli command "enable"
action 0002 cli command "sh run int t0"
action 0003 foreach line "$_cli_result" "\n"
action 0005 regexp "(source)\s(.*)" "$line" match sub1 sub2
action 0006 if $_regexp_result eq 1
action 0007 puts nonewline "$sub2"
action 0008 else
action 0009 regexp "(destination)\s([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" "$line" match sub1 sub2
action 0010 if $_regexp_result eq 1
action 0011 puts nonewline "$sub2"
action 0012 end
action 0013 end
action 0014 end
exit
end
R1#event manager run test
FastEthernet0/0
1.2.3.4
R1#
is this the shortest possible or is there a better way to do it while still using eem applet?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2021 08:45 AM
Another option using 4 lines.
event manager applet tunnel event none action 010 cli command "enable" action 020 cli command "show run interface tunnel2" action 030 regexp "tunnel source ([a-zA-Z0-9\/]+).*tunnel destination ([0-9\.]+)" "$_cli_result" match intf ip action 040 puts "$intf $ip" ! C1111#event manager run tunnel GigabitEthernet0/0/1 10.64.1.202 C1111#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2021 11:14 AM
Hey Daniel,
wow! thanks for this my friend!
I never considered the fact that the output of the sh run int tunnel command could be considered as one big string!
Many thanks for this a real eye opener for me
