05-05-2017 07:33 AM
Hello I'm wriring a script that look at the output command below:
Switch#sh cdp nei | i Nexus
Gig 2/0/1 162 S I Nexus1000 control0
Gig 2/0/35 162 S I Nexus1000 Eth 13/4
Gig 2/0/42 162 S I Nexus1000 Eth 13/3
Gig 2/0/6 162 S I Nexus1000 Eth 14/4
Gig 2/0/2 162 S I Nexus1000 Eth 14/3
And on trigger I have
$sxn1k_nic /\d+/ number
Gig [[$sx_mod]]/0/[[$sx_port]].*Eth [[$sxn1k_vem]]/[[$sxn1k_nic]]
When the regular expression is matched aginst the "sh cdp nei | i Nexus" Command (I used the Regular Expression Test Tool), since the first line contain control0 and not a number the match is:
16:21:27 Template matches
16:21:27 Gig (2)/0/(1).*Eth (13)/(4)
16:21:27 $sx_mod = '2'
16:21:27 $sx_port = '1'
16:21:27 $sxn1k_vem = '13'
16:21:27 $sxn1k_nic = '4'
16:21:27 SET: $donothing = "true"
As you see Gig 2/0/1 is not on the same line as Eth 13/4.
From my point of view is that I should define the regular expression with end of line caracter, I tried with $ (as in regex but is not working. It seams that Trigger-Template expression is not matched agains each line but on the whole text.
Where I'm wrong ?
05-05-2017 07:51 AM
The .* in regex will include end of line. Try using .+ instead. I am assuming you don't want any match on the first line.
http://www.tutorialspoint.com/ruby/ is a pretty good resource.
Let us know if this works, I didn't try it.