Friday, April 19, 2019

basic netmiko python script to search output and print result based on that output

Hello programmer folks,

I'm pretty horrible at programming.

My apologies if I put this question in the wrong section, I just figured this might make more sense for a network engineer who knows some automation.

if you're a network person who knows python scripting this might be an easy one for you.

I'm attempting to write a baby script for my job to make a task easier for myself.

All I want this script to do is get some output from a device on my network, spit that output onto my screen, then search the text it gets back and if it matches the text it finds, print "it is enabled".....if it does NOT find the text, then print "it is not enabled".

In this case, I just want the script to search interface g1/0/30 for the text of "spanning-tree portfast edge"

if it finds this exact text of "spanning-tree portfast edge" on the output it returns

then

print "porfast is enabled"

else

print "portfast is NOT enabled"

Eventually, I'll probably want to add the config lines to actually configure "spanning-tree portfast edge" if it does not find it, but for now I'll just go with the simpler one of it printing outputs based on the results that are returned on the interface show runs.

pretty simple, at least I have the first part working lol :) In the image below I put the syntax. I grayed out where I left off and couldn't get it to work. Tried a few different things, but everything was a failure.

https://imgur.com/a/NHTitux



No comments:

Post a Comment