VanDyke Software Forums

VanDyke Software Forums (
-   SecureCRT on the Mac (
-   -   Read cmds from file send string (

jdurrett 03-10-2020 06:47 PM

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

# crt.Sleep (60000)


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 I wont see prompt till the carriage return is sent on the last line of the text file i'm reading.

bgagnon 03-11-2020 07:42 AM

Hi jdurrett,

Your goal sounds almost exactly like the example script provided here in Python and VBScript form. :)

jdurrett 03-12-2020 08:42 AM

Taking a look ty
ty for the reference. I"ll dig into this and see how it works.

bgagnon 03-12-2020 09:41 AM

Hi jdurrett,

The author of that script I referenced pointed out they all wait for some sort of command prompt prior to moving on with the next line/command.

What we think might work better for you is the echo paste delay example script
(which sends a file line by line, waiting for each line to be echoed back before moving on to sending subsequent lines).

Alternatively, your script could be modified to replace the crt.Sleep(100) with this:


crt.Sleep() with Screen.Synchronous is not usually a successful combination. :)

All times are GMT -6. The time now is 01:39 AM.