Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > SecureCRT on the Mac

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-10-2020, 06:47 PM
jdurrett jdurrett is offline
Registered User
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 58
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
  #2  
Old 03-11-2020, 07:42 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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
Reply With Quote
  #3  
Old 03-12-2020, 08:42 AM
jdurrett jdurrett is offline
Registered User
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 58
Thumbs up Taking a look ty

ty for the reference. I"ll dig into this and see how it works.
Reply With Quote
  #4  
Old 03-12-2020, 09:41 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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)
crt.Sleep() with Screen.Synchronous is not usually a successful combination.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
macos , python , read file , send string

Thread Tools
Display Modes

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 03:29 AM.