Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-22-2016, 10:32 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
run python script from command line

Is there a way for me to run a python script from the command?

I get the following error

Code:
# python test2.py 
Traceback (most recent call last):
  File "test2.py", line 31, in <module>
    Main()
  File "test2.py", line 8, in Main
    crt.Screen.Synchronous = True
NameError: global name 'crt' is not defined
Reply With Quote
  #2  
Old 07-22-2016, 10:51 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,940
Hi rleon,

You can run scripts in SecureCRT by using the following:

SecureCRT.exe /Script "Path_to_Script.py"
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-22-2016, 11:38 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
hi

Im on MAC dont have an exe file.

Thanks
Reply With Quote
  #4  
Old 07-22-2016, 11:41 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,940
Hi rleon,

Sorry, for Mac OS, it would be:

/Applications/SecureCRT.app/contents/MacOS/SecureCRT /Script "Path_to_Script.py"
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 07-22-2016, 01:24 PM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
Thanks that worked ..

is there an option that doesnt force a new window to be opened? Ideally I would like to run it from the current session.
Reply With Quote
  #6  
Old 07-23-2016, 12:20 PM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,940
Hi rleon,

I am not quite sure what you need.

Does your script include code to logon the remote system?

You can use /S "session_name" to launch a session via the command-line. The /T option opens the connection in a tab. See the Using the Software / Command Line Options topics in SecureCRT's Help file for more info.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 07-25-2016, 08:26 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
I dont need to open a new session .. Just run it the script from the current session.

However :
Code:
/Applications/SecureCRT.app/contents/MacOS/SecureCRT /Script "Path_to_Script.py"
Opens a new window with a new session.
Reply With Quote
  #8  
Old 07-25-2016, 10:30 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,940
Hi rleon,

Are you connecting within the script?

If so, are you using the ConnectInTab() method?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 07-25-2016, 11:29 AM
bgagnon bgagnon is online now
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,940
Hi rleon,

Please elaborate on what you are trying to accomplish.

If already working in a session, using the command-line to launch a script that you want to execute *in the current session* is not the best way (and likely impossible).

You can use Script / Run to run the script. Or map it to run from a button on the Button Bar.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #10  
Old 07-26-2016, 08:12 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
ok .. I cant get the python script to loop through a list of hosts and run commands, so my goal was to wrap a secure crt python script into a shell script in on my mac. I can shell script the loop and everything else I need to do then execute the crt script with the commands I need ran from the shell script.

Im very confident it would work if i can just execute the crt script from the current session ...

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

def main():
        crt.Screen.Synchronous = True

        for g_strHost in open("/Users/rleon16/hosts", "r"):

         crt.Screen.Send("s " + line + '\r')

        crt.Screen.WaitForString("word: ")
        crt.Screen.Send("changeme" + chr(13))
        crt.Screen.WaitForString("-> ")
        crt.Screen.Send("exit" + chr(13))

        crt.Screen.WaitForString("# ")

        crt.Screen.Synchronous = False


main()
Reply With Quote
Reply


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 02:16 PM.