Script that queries cisco routers to pull the 'show dmvpn' output from the spoke hub routers. However we upgraded a hub router and the new IOS is showing now date/time info for "show dmvpn" command. Previous IOS versions only show 'never', and it throwing errors for newer IOS routers when using the script due to (\S+) only.
I tried to read up on Regular Expressions however couldn't make head/tails of how to join [3x] word/date/time.
Working:
if(pregmatch("/^\s+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+(\d+\.\d+\.\d+\.\d+)\s+(\S+)\s+(\S+)\s+(\S+)/",$line,$hit))
#show dmvpn
# Ent Peer NBMA Addr Peer Tunnel Add State UpDn Tm Attrb
----- --------------- --------------- ----- -------- -----
1 192.168.1.1 42.10.10.10 UP **never** DN
1 192.168.1.1 42.10.10.10 UP **never** DN
1 192.168.1.1 42.10.10.10 UP **never** DN
Not Working: Regex is failing on newer IOS that actually shows date/time for the Up/Down tunnel timers:
#show dmvpn
# Ent Peer NBMA Addr Peer Tunnel Add State UpDn Tm Attrb
----- --------------- --------------- ----- -------- -----
1 192.168.1.1 42.10.10.10 UP **08:59:16** DN
1 192.168.1.1 42.10.10.10 UP **04:11:24** DN
1 192.168.1.1 42.10.10.10 UP **2d13h** DN
1 192.168.1.1 42.10.10.10 UP **3w0d** DN
1 192.168.1.1 42.10.10.10 UP **5d00h** DN
I got as far assuming I need to add (\d+:\d+:\d+) next to the 2nd to last (\S+) in the code but not sure how to join them, and included the 3w0d & 5d00h in there as well.
This seems like a easy regex fix, however is currently beyond my scope of coding. I tried to also search for an answer but everyone keeps using different terminology for 'regular expressions' & 'regex'
Your regexp is only suppose to match the lines if you are in Tunnel mode :$tunnel_int = TRUE
But the code example you gave us does not contain a string starting with "Tunnel", so you are not passing in tunnel mode, so you never try to match the regexp. That's why even if the regexp is correct, the script is not working.
Your problem is an algorithm problem, not a regexp problem. But since we don't know what you are trying to do and what you are trying to test, it's hard to help.
if you don't have developper skills to maintain this, maybe you should get the help of a freelance developper to help you understand your needs and adapt the code.
If you have more specific infos then you can ask for a more precise help on a subject.
Good luck for you project.