View Single Post
  #1  
Old 03-10-2020, 06:47 PM
jdurrett jdurrett is offline
Registered User
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 57
Send a message via Yahoo to jdurrett
Read cmds from file send string

I used to do everything on Windows and wrote lengthy vbscripts. Now my employment has changed and I'm using a Mac with SecureCRT and trying to get a handle on python scripting. sigh

I would like to start with a simple script to read commands from a file and send to screen. Platform is unix that im executing against.

#$language = "python"
#$interface = "1.0"

#
# Description:


def Main():

szPrompt = "[root@cenx-fault-1 _data]#"
objTab = crt.GetScriptTab()
objTab.Screen.Synchronous = True

objTab.Screen.IgnoreEscape = True

# Opening file
file1 = open('cmds.txt', 'r')
count = 0

# Using for loop
print("Using for loop")
for line in file1:
count += 1
send_stuff = ("Line{}: {}".format(count, line.strip()))
crt.Screen.Send (send_stuff)
crt.Sleep (100)
# Closing files
file1.close()

# crt.Sleep (60000)

Main()

Appreciate your assistance. Tried searching thru forum posts but didnt find what I was looking for.

Just want to read a line, sleep short pause and send next line...the commands are going to be multiline for unix..so I wont see prompt till the carriage return is sent on the last line of the text file i'm reading.
Reply With Quote