VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   run python script from command line (https://forums.vandyke.com/showthread.php?t=12412)

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

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


bgagnon 07-22-2016 10:51 AM

Hi rleon,

You can run scripts in SecureCRT by using the following:

SecureCRT.exe /Script "Path_to_Script.py"

rleon 07-22-2016 11:38 AM

hi

Im on MAC dont have an exe file.

Thanks

bgagnon 07-22-2016 11:41 AM

Hi rleon,

Sorry, for Mac OS, it would be:

/Applications/SecureCRT.app/contents/MacOS/SecureCRT /Script "Path_to_Script.py"

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 :
Code:

/Applications/SecureCRT.app/contents/MacOS/SecureCRT /Script "Path_to_Script.py"
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 ...

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()



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