All Products
Search
Document Center

:Use a Cron job to execute Shell scripts on a host

Last Updated:Apr 14, 2025

SchedulerX allows you to execute specific scripts on self-managed hosts or Elastic Compute Service (ECS) instances. This topic describes how to deploy an agent on a host, associate the host with a SchedulerX application, and create a Cron job in the SchedulerX console to execute Shell scripts on the host based on specified rules.

Prerequisites

  • An ECS instance or a host is available. For more information, see Get started with ECS.

    The Java Development Kit (JDK) environment is installed on the ECS instance or host. The JDK environment is required for starting the agent.

  • SchedulerX is activated. For more information, see Activate SchedulerX.

Note

Make sure that the server and the SchedulerX service are in the same region.

Background information

In this example, an agent is used to associate the host with SchedulerX and create a Cron job in the SchedulerX console to execute Shell scripts. You can also use one of the following methods to connect to SchedulerX:

Overview

You can use an agent to quickly connect to SchedulerX and schedule jobs. The procedure includes four steps:

  1. Associate your host with SchedulerX: Create an application in the SchedulerX console and associate the host with the application.

  2. Create a job for the host: Create a job in the SchedulerX console and make sure that the job is associated with the application.

  3. Run the job: In the SchedulerX console, select the instance that you want to manage and schedule the job to the instance.

  4. View results: You can query and analyze the execution log of a job in the SchedulerX console.

Step 1: Associate your host with SchedulerX

1.1 Create an application

  1. Log on to the SchedulerX console. In the left-side navigation pane, click Application Management. On the Application Management page, select default namespace in the upper part of the page and click Create application. In the Create application panel, configure the Application Name and Application ID parameters, set the app type parameter to general app and Release to Professional Edition, configure the parameters in the Advanced Configuration section based on your business requirements, and then click Next Step.

    image

    Important

    You must specify a region and a namespace to make sure that resources are deployed in the desired location.

  2. In the Notification configuration step, configure the Notification channel and Notify contact parameters. The application is created.

1.2 Manually deploy the agent

Download and deploy the agent. For more information, see the Manually deploy the agent section of the Use the SchedulerX agent to connect an application to SchedulerX (script or HTTP jobs) topic.

Note

Make sure that the runtime environment is JDK 1.8 to 14. If you use a JDK version later than 14, remove the -XX:+UseConcMarkSweepGC option from the schedulerxAgent/bin/start.sh file in the agent installation directory.

image

Step 2: Create a job for the host

2.1 Create a job

  1. In the left-side navigation pane, click Task Management. On the Task Management page, click Create task.

  2. In the Basic Configuration step, configure the Task name and Application ID parameters, and set the Task type parameter to ScriptTask, Script to shell, Execute Command to echo Agent connects to SchedulerX, File format to unix, and Execution mode to Stand-alone operation. Configure the parameters in the Advanced Configuration section based on your business requirements. For more information, see Basic parameters of the Job management topic.

    image

  3. In the Timing configuration step, set the Time type parameter to cron and use the build tool to generate a cron expression. Example: 0 * * * * ?. This expression specifies that the job runs every minute. Configure the parameters in the Advanced Configuration section based on your business requirements. For more information, see Parameters for job scheduling of the Job management topic.

    image

  4. In the Notification configuration step, configure the Notification channel and Notify contact parameters. The job is created. For more information, see Notification channel and contact person of the Job management topic.

2.2 Verify the results

You can find the job on the Task Management page or click Execution List in the left-side navigation pane and click the Task instance List tab.

Step 3: Run the job

On the Task Management page, find the job that you want to manage and click Run once in the Operation column.

Step 4: View the results

  1. In the left-side navigation pane, click Execution List. On the Task instance List tab, find the job that you want to manage and click Log in the Operation column.

  2. If the log displays Agent connects to SchedulerX, the Shell script is executed by the job.

    image

References

FAQ