Run shell cron jobs on a specified host
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.
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:
-
Associate the host with SchedulerX: Create an application in the SchedulerX console and associate your target host with the application.
-
Create a task for the host: Create a task in the console and associate it with the application you created.
-
Run the task: In the console, select the appropriate instance and run the task.
-
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
-
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.
ImportantEnsure you select the correct region and namespace.
-
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.
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
-
In the left-side navigation pane, choose Task Management, and then click Create Task.
-
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. -
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.
-
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
-
Go to Execution List > Task Instance List. Find the relevant task instance and click Log.
-
The output
Agent connects to SchedulerXin the log confirms that the shell script task ran successfully.
Related documentation
-
For definitions of SchedulerX-specific terms, see Glossary.
-
For detailed steps on how to create an application in SchedulerX, see Application management.
-
For detailed steps on how to connect to SchedulerX using an agent, see Agent connection (for script or HTTP tasks).
-
For detailed steps on how to create a task in SchedulerX, see Task management.
FAQ
-
If you cannot log on to a remote ECS instance, you may need to add a security group rule. For more information, see Add a security group rule on the Inbound tab when connecting to an instance in a VPC.
-
If the connection times out when you use the wget command on an ECS instance to download the agent, enable a public IP address for the instance or see Upload or download files (Linux).
-
For a summary of common issues, see SchedulerX FAQ.