All Products
Search
Document Center

SchedulerX:Script jobs

Last Updated:May 07, 2025

This topic describes how to create script jobs by writing Shell, Python, or PHP scripts.

Introduction

The following figure shows how to use script jobs.

yuque_diagram (1)

  1. To use script jobs, deploy schedulerx-agent on the target device in advance to communicate with the server, receive script execution commands, and return execution results.

  2. Deploy the dependencies required for running scripts on the device in advance, such as Python dependency libraries and dependent files.

  3. Each time a script is executed, schedulerx-agent forks a child process to run the script. This child process does not occupy the memory of schedulerx-agent, but it occupies the memory of the device (the specific memory consumption depends on the script content). If a large number of script jobs are running simultaneously, the device may run out of memory. We recommend that you use Kubernetes jobs to run scripts through pods in scenarios in which a large amount of computing resources are required to run scripts.

Prerequisites

Create a script job

Log on to the Distributed Task Scheduling Platform, click Task Management in the left-side navigation pane, and create a job on the Task Management page. When you create a job, select ScriptTask for Task type.

image

Step 1: Select a script language

Select shell, python, or php from the Script drop-down list as the script language.

Step 2: Select an execute command

Commands for executing the script in different languages:

  • Shell script: The default command is /bin/sh.

  • Python script: The default command is python. You can change the command to python2 or python3.

  • PHP script: The default command is php.

Step 3: Select a file format

The line feed varies when you select unix or windows for File format.

  • To execute the script on a Windows system, select windows.

  • To execute the script on Linux, Unix, or macOS, select unix.

Important

When the script source is on a Windows system but needs to run on a Linux system, select unix for File format.

Step 4: Select an execution mode

Access prerequisite: schedulerxAgent is deployed in advance to run scripts. For more information, see Use the SchedulerX agent to connect an application to SchedulerX (Script or HTTP jobs).

Execution mode:

  • Stand-alone operation: If you deploy multiple SchedulerX agents and set Execution mode to Stand-alone operation, SchedulerX randomly selects a SchedulerX agent to run the script.

  • Broadcast run: If you deploy multiple SchedulerX agents and set Execution mode to Broadcast run, SchedulerX broadcasts the script to all the SchedulerX agents. This way, the script runs on all SchedulerX agents at the same time. This setting is preferred for batch O&M.

  • Shard run: See Create a Python sharding job.

Write scripts

After a script job is created, a script template is generated by default based on the script language. You can modify the script content by clicking EditScript on the Task Management page.

image

Historical script versions

Professional Edition applications can use the historical script version feature. On the EditScript page, turn on the Historical versions switch to go to the version comparison page.

  • The left side shows the current version, and the right side shows the historical version.

  • Click the dropdown box to view historical version information, including version notes and creation time.

  • After you modify the script content, click Confirm. You will be prompted to enter a new version name.

image

Demo

Distributed processing based on job broadcasting

  1. Connect to two schedulerx-agents.

  2. Create a new script job with Script set to shell and Execution mode set to Broadcast run. The following figure shows the script content.

    image

  3. Click Run once in the Operation column of the job.

  4. Click Execution List in the left-side navigation pane. On the Execution List page, click Log in the Operation column of the job instance to view the content executed by each machine.

    • The following figure shows the running logs of 172.16.13.125. According to the logs, the shard ordinal number obtained is 1, and the total number of shards is 2.

      image

    • The following figure shows the running logs of 172.16.13.120. According to the logs, the shard ordinal number obtained is 0, and the total number of shards is 2.

      image

Distributed processing based on job sharding

  1. Create a new script job with Script set to shell and Execution mode set to Shard run. The following figure shows other job configurations.

    image

  2. After you create the job, click EditScript for the job. The following figure shows the script content.

    image

  3. Click Run once in the Operation column of the job.

  4. Click Execution List in the left-side navigation pane. On the Execution List page, click Log in the Operation column of the job instance to view the sharding parameters of each machine.

    • According to the logs, two shards (hangzhou and beijing) are allocated to and run on 172.16.13.120.

    • Two shards (shenzhen and shanghai) are allocated to and run on 172.16.13.125.

    image

References

For system built-in parameters, see System variables of scripts.