Running Python Scripts
JAMS provides three Execution Methods to let you easily run Python scripts. Each Execution Method is specific to the supported operating system. You will need to choose the appropriate one based on your environment.
The following Execution Methods are available:
- PythonSSH – Execute Python code on an SSH Agent.
- PythonUnix – Execute Python code on a Unix Agent.
- PythonWindows – Execute Python code on a Windows Agent or JAMS Scheduler.
Running Python Scripts on an SSH Agent
JAMS has an Execution Method to let you run Python code on an SSH Agent. With this Execution Method, you can copy and paste your code into the Job and have JAMS run it.
Before you Begin
- Ensure you have JAMS AgentX installed.
- Ensure Python is installed on the JAMS Agent.
- Ensure you have a JAMS Credential created to run the Job in JAMS. This credential should have permissions to the relevant Agent. See Working with User Credential Definitions for more information.
Using the PythonSSH Execution Method
- Click Execution Methods from the JAMS Shortcuts menu.
- Double-click the PythonSSH Execution Method to review its properties.
- Click the Template tab.
- Enter the location of the Python executable on the Agent. The default value of this is:
#!/usr/bin/env python
<<JAMS.Source>>
- Click Save and Close.
- Click Definitions from the JAMS Shortcuts menu.
- In the Folder Navigator, select a Folder where the Job will be saved.
- Click + to add a new Job.
- In the Name field, enter a name for the Job.
- In the Execution Method field, select PythonSSH.
- Click Ok.
- On the Source tab, paste your Python code.
- Click the Schedule tab.
- As needed, schedule when the Job will run.
- Click the Properties tab.
- In the Agent field, select the JAMS Agent that will run the Job.
- In the Execute As field, select the JAMS Credential that will be used to run the Job.
- Click Save and Close.
Running Python Scripts on a Unix Agent
JAMS has an Execution Method to let you run Python code in a Unix environment. With this Execution Method, you can copy and paste your code into the Job and have JAMS run it.
Before you Begin
- Ensure you have a JAMS AgentD installed. See JAMS AgentD for Linux/Unix for more information.
- Ensure Python is installed on the JAMS Agent.
- Ensure you have a JAMS Credential created to run the Job in JAMS. This credential should have permissions to the relevant Agent. See Working with User Credential Definitions for more information.
Using the PythonUnix Execution Method
- Click Execution Methods from the JAMS Shortcuts menu.
- Double-click the PythonUnix Execution Method to review its properties.
- Click the Template tab.
- Enter the location of the Python executable on the Agent. The default value of this is:
#!/usr/bin/env python <br /> \<\<JAMS.Source\>\> - Click Save and Close.
- Click Definitions from the JAMS Shortcuts menu.
- In the Folder Navigator, select a Folder where the Job will be saved.
- Click + to add a new Job.
- In the Name field, enter a name for the Job.
- In the Execution Method field, select PythonUnix.
- Click Ok.
- On the Source tab, paste your Python code.
- Click the Schedule tab.
- As needed, schedule when the Job will run.
- Click the Properties tab.
- In the Agent field, select the JAMS Agent that will run the Job.
- In the Execute As field, select the JAMS Credential that will be used to run the Job.
- Click Save and Close.
Running Python Scripts on Windows Agent
JAMS has an Execution Method to let you run Python code in a Windows environment. With this Execution Method, you can copy and paste your code into the Job and have JAMS run it.
You can also have your Python code in a separate .PY file and reference it within a JAMS Job by using the Command Execution Method. Both Execution Methods are described in the sections below.
Before you Begin
- Ensure you have a JAMS Windows Agent installed. See JAMS Agent for Windows for more information.
- Ensure Python (Python.exe) is installed on the JAMS Windows Agent or JAMS Scheduler.
- Ensure you have a JAMS Credential created to run the Job in JAMS.
Using the PythonWindows Execution Method
- Click Execution Methods from the JAMS Shortcuts menu.
- Double-click the PythonWindows Execution Method to review its properties.
- Click the Properties tab.
- From the list of properties, go to the Command property.
- Update or verify the property that lists the location of the Python.exe on your JAMS Windows Agent or JAMS Scheduler. It will look similar to the following: C:\Users\MyAccount\AppData\Local\Programs\Python\Python314\python.exe "{0}". Ensure the "{0}" is included.
- Click Save and Close.
- Click Definitions from the JAMS Shortcuts menu.
- In the Folder Navigator, select a Folder where the Job will be saved.
- Click + to add a new Job.
- In the Name field, enter a name for the Job.
- In the Execution Method field, select PythonWindows.
- Click Ok.
- On the Source tab, paste your Python code.
- Click the Schedule tab.
- As needed, schedule when the Job will run.
- Click the Properties tab.
- In the Agent field, select the JAMS Agent that will run the Job. Leave it blank to have it run on the JAMS Scheduler.
- In the Execute As field, select the JAMS Credential that will be used to run the Job.
- Click Save and Close.
Using the Command Execution Method to run Python Scripts on Windows
- Click Definitions from the JAMS Shortcuts menu.
- In the Folder Navigator, select a Folder where the Job will be saved.
- Click + to add a new Job.
- In the Name field, enter a name for the Job.
- In the Execution Method field, select Command.
- Click Ok.
- On the Source tab, paste your Python code. You will need to reference the location of the python.exe and .py files. It may look similar to the following:
c:\\Users\\MyAccount\\AppData\\Local\\Programs\\Python\\Python314\\python.exe c:\\hello.py
- Click the Schedule tab.
- As needed, schedule when the Job will run.
- Click the Properties tab.
- In the Agent field, select the JAMS Agent that will run the Job. Leave it blank to have it run on the JAMS Scheduler.
- In the Execute As field, select the JAMS Credential that will be used to run the Job.
- Click Save and Close.