Run shell cron jobs on a specified host

Updated at:
Copy as MD

SchedulerX allows you to run specific scripts on your self-managed hosts or 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 to run a shell script on the host on a schedule.

Prerequisites

  • You have an available ECS instance or host. For more information, see ECS Quick Start.

    The ECS instance or host has a Java Development Kit (JDK) environment installed to support agent startup.

  • You have activated SchedulerX. For more information, see Activate SchedulerX.

Note

Ensure that your host or ECS instance and SchedulerX are in the same region.

Background

This example demonstrates how to use an agent to associate a host with SchedulerX and create a shell script to run as a cron job. You can also connect to SchedulerX in the following ways:

Overview

To quickly connect to SchedulerX using an agent and run a one-off task, follow these four steps:

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

  2. Create a task for the host: Create a task in the console and associate it with the application you created.

  3. Run the task: In the console, select the appropriate instance and run the task.

  4. View the results: Check the execution log of the task in the console.

Step 1: Associate a host with SchedulerX

1.1 Create an application

  1. Log on to the SchedulerX console. In the left-side navigation pane, choose Application Management. Select default namespace from the Namespace drop-down list, and then click Create Application. Enter an Application Name and Application ID. Set Application Type to general app and Version to Professional Edition. Configure Version as needed, and then click Next.

    Important

    Ensure you select the correct region and namespace.

  2. On the Notification Configuration wizard page, enter the required information, select a Notification Channel and specify a Alert Contacts to create the application.

1.2 Manually deploy the agent

Download and deploy the agent. For more information, see Manually deploy the agent.

Note

The runtime environment requires JDK version 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.

Step 2: Create a task for the host

2.1 Create a task

  1. In the left-side navigation pane, choose Task Management, and then click Create Task.

  2. On the Basic Configuration wizard page, enter a Name and an Application ID. For Job Type, select script task. For Script Language, select shell. For Execution Command, enter echo Agent connects to SchedulerX. For File Format, select unix. For execution mode, select stand-alone operation. Configure the Advanced Configuration settings as needed. For more information, see Basic configuration parameters.

  3. On the Schedule Configuration wizard page, set Time Type to cron. Use the built-in tool to generate a Cron Expression. For example, the expression 0 * * * * ? runs the task once every minute. Configure Advanced Configuration as needed. For more information about the parameters, see Timing parameter description.

  4. On the Notification Configuration wizard page, enter the required information, select a Notification Channel and specify a Alert Contacts to complete the task creation. For more information about the parameters, see Description of notification channels and contacts.

2.2 Verification

Go to Task Management > Task Instance List. The task you created appears in the list.

Step 3: Run the task

In Task Management, find the task you created, enable it, and click Run Once.

Step 4: View the results

  1. Go to Execution List > Task Instance List. Find the relevant task instance and click Log.

  2. The output Agent connects to SchedulerX in the log confirms that the shell script task ran successfully.

Related documentation

FAQ