Created
March 30, 2016 05:55
-
-
Save meeuw/5211fd9627e73582a5bcbb3508093080 to your computer and use it in GitHub Desktop.
quick hack to log port status of cisco switches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import telnetlib | |
import time | |
prompt = os.environ['PROMPT']+">" | |
if 'USERN' in os.environ: | |
usern = os.environ['USERN'] | |
else: | |
usern = None | |
passw = os.environ['PASSW'] | |
host = os.environ['HOST'] | |
print [passw, usern] | |
tn = telnetlib.Telnet(host) | |
if usern: | |
tn.read_until("login: ") | |
tn.write(usern+"\n") | |
tn.read_until("Password: ") | |
tn.write(passw+"\n") | |
#while 1: print [tn.read_some()], | |
tn.read_until(prompt) | |
tn.write("terminal length 0\n") | |
tn.read_until(prompt) | |
while 1: | |
tn.write("show int\n") | |
filename = "show_int-%s.txt" % host | |
with open(filename+".tmp", "w") as f: | |
for line in tn.read_until(prompt).split("\n"): | |
w = None | |
if line.startswith("FastEthernet"): | |
w = line.strip() | |
elif line.startswith("GigabitEthernet"): | |
w = line.strip() | |
if w: | |
f.write(w+"\n") | |
os.rename(filename+".tmp", filename) | |
os.system("git commit -am '' --allow-empty-message") | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment