Tips
Ubuntu ls -lt (shows date modified) or ltr reverse order.
sudo apt-get install less
rm switch192.168.122.* (Removing a file plus the wildcard)
| #!/usr/bin/env python | |
| import getpass | |
| #import sys | |
| import telnetlib | |
| # Get Username and Password | |
| user = raw_input("Enter your username: ") | |
| password = getpass.getpass() | |
| # Open file with list of switches | |
| f = open ("myswitches") | |
| # Telnet to each switch and cofigure it | |
| for line in f: | |
| print "Getting running-config " + (line) | |
| HOST = line.strip() | |
| tn = telnetlib.Telnet(HOST) | |
| tn.read_until("Username: ") | |
| tn.write(user + "\n") | |
| if password: | |
| tn.read_until("Password: ") | |
| tn.write(password + "\n") | |
| tn.write("terminal length 0\n") | |
| tn.write("show run\n") | |
| tn.write("exit\n") | |
| readoutput = tn.read_all() | |
| saveoutput = open("switch" + HOST, "w") | |
| saveoutput.write(readoutput) | |
| saveoutput.write("\n") | |
| saveoutput.close | |
| print tn.read_all() |
No comments:
Post a Comment