#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
Hi jdurrett,
Your goal sounds almost exactly like the example script provided here in Python and VBScript form. ![]()
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
![]()
ty for the reference. I"ll dig into this and see how it works.
|
#4
|
|||
|
|||
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: Code:
crt.Screen.WaitForString(send_stuff) ![]()
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
macos , python , read file , send string |
Thread Tools | |
Display Modes | |
|
|