VanDyke Software Forums

VanDyke Software Forums (
-   Scripting (
-   -   run python script from command line (

rleon 07-22-2016 10:32 AM

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


# python
Traceback (most recent call last):
  File "", line 31, in <module>
  File "", line 8, in Main
    crt.Screen.Synchronous = True
NameError: global name 'crt' is not defined

bgagnon 07-22-2016 10:51 AM

Hi rleon,

You can run scripts in SecureCRT by using the following:

SecureCRT.exe /Script ""

rleon 07-22-2016 11:38 AM


Im on MAC dont have an exe file.


bgagnon 07-22-2016 11:41 AM

Hi rleon,

Sorry, for Mac OS, it would be:

/Applications/ /Script ""

rleon 07-22-2016 01:24 PM

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.

bgagnon 07-23-2016 12:20 PM

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.

rleon 07-25-2016 08:26 AM

I dont need to open a new session .. Just run it the script from the current session.

However :

/Applications/ /Script ""
Opens a new window with a new session.

bgagnon 07-25-2016 10:30 AM

Hi rleon,

Are you connecting within the script?

If so, are you using the ConnectInTab() method?

bgagnon 07-25-2016 11:29 AM

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.

rleon 07-26-2016 08:12 AM

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 ...


# $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


All times are GMT -6. The time now is 01:34 PM.