Closed methridge closed 8 years ago
For sending configuration commands to the active session, my thought is to just assume the user knows what commands they need to send, therefor just send it check for the echo back and be done.
def SendConfigCommand(session, command):
#This function sends configuration commands to the session
tab = session['tab']
# Send command
tab.Send(command + "\n")
# Ignore the echo of the command we typed (including linefeed)
tab.WaitForString(command.strip())
With this in mind, I'm using another function to write a few lines to the "log file" we've been appending to in this script.
def WriteLogLine(command, filename):
now = GetDateString(settings['date_format'])
textToAdd = "\n/********************************************/\n\*\n\* " + \
now + "\n\* " + command.strip() + \
"\n\*\n/********************************************/\n\n"
f = file(filename, 'ab')
f.write(textToAdd)
f.close()
Not sure if you want to include both of these into the ciscolib.py. Or just keep them in the script.
I'm attaching the script that these have been used in so you can see what I'm working with. ClearAAA.txt
Sorry for the delay - just now catching up with work and everything else, but hopefully I'll find time to take a look at this soon.
I'm also trying to weigh in my mind if we just have "SendConfigCommand" as a function that sends the command without capturing output, or if we might want to have the function account for multiple commands that are encapsulated by a "conf t" and "end". For example, it could accept a list of commands -- it would then send the "config t" before sending each command in the list individually, and finally sending the "end". It would be easy enough to check if the input was a string or a list, and if a string, just send the one command.
The downside is that if this was ever used in a loop, it would be messy going in and out of config mode all the time.
No worries. I've been working on another script to load a base config from a file. Marking which lines fail. So, I have something that mostly works. Again there are issues. For example, the banner command doesn't echo back the same. So something might have to be done to not check for the command echo. ConfigLoad.txt
Completed working Config_Load script. We can adjust later and pull out some functions as desired.
Greetings: I've been working on another script that is used in the decommissioning process. It clears AAA and creates a local username / password. The idea is to have a single log file rather than one per command.
Based on this I had a couple of questions about the WriteOutput function.
--ME