Python writing to file in SecureCRT
New to Python and scripting in general. I'm writing a script that I am connecting to a host, looping through some commands and disconnecting. Then connecting to the next host and running through the same commands...I would like to capture the results of those commands to a file. I create a file and open it for capture but I can't figure out what is needed to get the data to save to the file. Code is below.
from datetime import datetime
strPrompt = ">"
commands = ["show alarms\r", "exit\r"]
with open ("C:/_user_Scripts/Python_Files/OLTs.csv") as f: # open host file
OLTReader = csv.DictReader(f)
for row in OLTReader:
outfile_name = str(datetime.now().strftime('%Y%m%d%H%M%S')) + "_log_%s" %(row["CLLI"]) #name capture file
crt.Screen.Send("telnet " + row["IP_Address"] + '\r') # connect to device
with open ("C:/_user_Scripts/Python_Files/userpw.csv") as userpw:
userpw = csv.DictReader(userpw)
for row in userpw: # Login to device calling user/pw from file
crt.Screen.Send(row["User"] + '\r')
crt.Screen.Send(row["Password"] + '\r')
with open(outfile_name, "w") as file: # open log file
for command in commands: # loop through commands and write output to file
any input you can provide is greatly appreciated. the file.write() is commented out and where i'm getting hemmed up.
Sounds to me like you are unnecessarily re-inventing the wheel.
See the example script in this forum post.
|Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)|
|Display Modes||Rate This Thread|