Run a created Cloud Assistant command on one or more ECS instances. Each instance executes independently.
Prerequisites
The target instances must meet the following requirements:
The instances are in the Running state.
The Cloud Assistant Agent must be installed. For more information, see Install the Cloud Assistant Agent.
To use new features for scheduled tasks, such as running a command at a fixed interval, running a command only once at a specified time, or specifying a year or time zone in a cron expression, make sure that your Cloud Assistant Agent is one of the following versions or later:
Linux: 2.2.3.282
Windows: 2.1.3.282
If the
ClientNeedUpgradeerror code is returned, you must update the agent to the latest version. For more information, see Upgrade or disable automatic upgrades for the Cloud Assistant Agent.
Background
When you call an API operation to run a command, you can select a maximum of 100 instances. You can request an increase in the "Maximum number of instances supported for command execution" quota. For more information about how to view and increase resource quotas, see View and increase resource quotas.
If you select more than 100 instances in the ECS console, the system runs the command in batches.
Procedure
Run a command in the ECS console
In the upper-left corner of the page, select a region and resource group.
On the My Commands tab, find the target command and click Run in the Actions column.
In the Run Command panel, configure the following parameters.
In the Command Information section, verify the command content and configure the following parameters.
Parameter
Description
Command
Click View command content to view the command.
Execution Plan
Select when to run the command.
Immediate execution: Runs the command immediately.
After the next startup of the system: Runs the command the next time the instances start.
After each system startup: Runs the command each time the instances start.
Perform Only Dry Run: Validates request parameters, instance execution environments, and Cloud Assistant Agent status without running the command.
Timing execution: Runs the command at a fixed interval, a specific time, or on a cron schedule. Options:
Run at Fixed Interval: Specify a rate expression to run the command at a fixed interval in seconds, minutes, hours, or days.
NoteInterval limits:
The interval ranges from 60 seconds to 7 days and must exceed the timeout period of the scheduled task.
The interval is measured between consecutive executions, not including execution time. For example, if the interval is 5 minutes and a run takes 2 minutes, the next run starts 3 minutes after the previous run completes.
The first execution starts after one full interval. For example, a task with a 5-minute interval runs 5 minutes after creation.
Run Only Once at Specified Time: Specify a time and time zone to run the command once.
For example, setting Execution Time to May 17, 2022, 17:30:50 and Time Zone to (GMT+08:00) Asia/Shanghai runs the command once at 17:30:50 on May 17, 2022 (UTC+8).
Run on Clock-based Schedule: Use a cron expression to run the command on a schedule. Specify the frequency at a granularity of seconds, minutes, hours, day of the month, month, day of the week, or year, and select a time zone from the Time Zone drop-down list. See Cron expressions.
NoteThe minimum interval must be 10 seconds or longer and must exceed the timeout period of scheduled executions.
For example, setting Execution Frequency to 0 0 12 ? * WED 2022 and Time Zone to (GMT+08:00) Asia/Shanghai runs the command at 12:00:00 every Wednesday in 2022 (UTC+8).
Username
The username to run the command on ECS instances.
For security purposes, run Cloud Assistant commands as a regular user based on the principle of least privilege. See Run Cloud Assistant commands as a RAM user.
By default, commands run as the root user on Linux and the system user on Windows.
Timeout Period
The Timeout Period for running the command on instances. If the task times out, Cloud Assistant forcefully terminates the task process.
Unit: seconds. Default: the Timeout Period specified for the command.
NoteThis timeout applies only to the command task. Changing it does not affect the timeout of the command itself.
Tag
Add tags to the command task by specifying Tag Key and Value.
In the Select Instances and Select Managed Instances sections, select the target instances.
You can search for instances by instance ID, name, or tag, and filter by Cloud Assistant Agent status.
NoteManaged instances are non-Alibaba Cloud servers that are managed by Cloud Assistant. For more information, see Alibaba Cloud managed instances.
Click Run.
Run a command by using Alibaba Cloud CLI
Before using Alibaba Cloud CLI, install it on your computer. Installation methods vary by operating system:
(Optional) If the instance is not in the Running (
Running) state, callStartInstanceto start it.aliyun ecs StartInstance --InstanceId 'i-bp1f4f6o8lv0wqof****'NoteValues in single quotation marks ('') are examples. Replace them with your actual values.
See StartInstance.
(Optional) Call
DescribeCloudAssistantStatusto check whether Cloud Assistant Agent is installed on the instances.aliyun ecs DescribeCloudAssistantStatus --RegionId 'cn-hangzhou' \ --InstanceId.1 'i-bp1f4f6o8lv0wqof****'If Cloud Assistant Agent is installed,
CloudAssistantStatusis true in the response. Otherwise, callInstallCloudAssistantto install it. See DescribeCloudAssistantStatus and InstallCloudAssistant.Call
InvokeCommandto run a Cloud Assistant command on one or more instances.aliyun ecs InvokeCommand --RegionId 'cn-hangzhou' \ --InstanceId.1 'i-bp1f4f6o8lv0wqof****' \ --InstanceId.2 'i-bp137qu6142s3mhm****' \ --CommandId 'c-hz018qp243j****'The following table describes the main parameters. See InvokeCommand.
Parameter
Example
Description
RegionId
cn-hangzhou
The region ID.
InstanceId.1
i-bp1f4f6o8lv0wqof****
The ID of the first instance to run the command on.
InstanceId.2
i-bp137qu6142s3mhm****
The ID of the second instance to run the command on.
CommandId
c-hz018qp243j****
The command ID.