Hmm... I found a use case where my solution doesn't work cvachovecj Was trying to weed out unknown SNMP communities on routers of a company we just merged with. I modified this to look for "^snmp-server community .*" instead of the NTP. Had it look for either community in the config block and ran it. Worked for most of the communities on my test router, except for one. Tried a couple different things and couldn't get it to work. I end up with in the config:
! 1- unrelated config lines.
snmp-server community badcommunity RO
snmp-server community validcommunity1 RO
snmp-server community validcommunity2 RW
! 2 - unrelated config lines
What I think is happening is that a config block has to be at least 2 lines, not sure if this part is true or not. So, I have it starting with "^snmp-server community" and ending with basically anything (ie: ".*", have tried a couple things). So, I'm thinking it iterates through 3 blocks. The first one starting with "snmp-server community badcommunity" and ending with the next line (snmp-server community validcommunity1"). Now, since I'm looking for "snmp-server community validcommunity1" in the config block and its there, this passes (even though I don't want it to). The next 2 times it iterates through, it uses the other snmp-server community lines as start lines and the next lines as stop, and they also pass.
So, the problem is that I really only want to look at one line in the config, not 2. But I don't think I can get a config-block to be only one line. Hmm.. You know there are probably a couple other things to try, if any of them work I'll post here... But, as of now I don't think this will work.
However, I am sure you can see the way that we NEED this ability, and I'd preferably have it done in a way that isn't kind of "hacking" the server!!
Thoughts?! (I will let you know if any of my other potential hacks work, I don't expect them to)...