Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting

Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-08-2019, 07:31 AM
v777201 v777201 is offline
Registered User
Join Date: Aug 2019
Posts: 1
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.

import SecureCRT
import csv
import time
from datetime import datetime

strPrompt = ">"
commands = ["show alarms\r", "exit\r"]

def main():
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.

Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -6. The time now is 05:47 PM.