After you create a Cloud Assistant command, you can run it on one or more Elastic Compute Service (ECS) instances. The execution status and results of the command on multiple instances do not affect each other.

Prerequisites

Before you run a Cloud Assistant command on ECS instances, make sure that the instances meet the following requirements:
  • The instances are in the Running (Running) state.
  • The Cloud Assistant client is installed on the instance. For more information, see Install the Cloud Assistant client.
    If you are concerned about recurring tasks, make sure that the version of the Cloud Assistant client is not earlier than the following ones. A recurring task is a task that is scheduled to run a command at a specified interval, only once at a specified time, or on a schedule defined by a cron expression with a specified year or time zone.
    • Linux: 2.2.3.282
    • Windows: 2.1.3.282

    If the ClientNeedUpgrade error code is returned after a recurring task is executed, update the Cloud Assistant client to the latest version. For more information, see Upgrades or disable upgrades for the Cloud Assistant client.

Background information

  • You can call an API operation to run a command on up to 50 instances.
  • If you select more than 50 instances to run a command in the ECS console, the system runs the command on the instances in batches.
  • You can run Cloud Assistant commands up to 5,000 times within a region per day. This quota may increase based on your ECS usage. For more information about how to view the quota, see Step 1: View resource quotas.
    Note You can also call the DescribeAccountAttributes operation with the AttributeName.N parameter set to max-axt-invocation-daily to query the maximum number of times that you can run Cloud Assistant commands within in a region per day.

Procedure in the ECS console

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Maintenance & Monitoring > ECS Cloud Assistant.
  3. In the top navigation bar, select a region.
  4. On the Commands tab of the Cloud Assistant page, find the command that you want to run and click Create Task in the Actions column.
  5. In the Create Task panel, configure parameters.
    1. In the Command Information section, check the command content and configure command parameters and Username.
      Parameter Description
      Command Click View to check the command.
      Implementation Plan Select a command execution plan.
      • Immediate execution: The command is run immediately after you click Run or Execute and Save.
      • After the next startup of the system: The command is run the next time the selected instances are started after you click Run or Execute and Save.
      • After each system startup: The command is run each time the selected instances are started after you click Run or Execute and Save.
      • Run on Schedule: The command is run at a specified interval, at a specified time, or on a schedule after you click Run or Execute and Save. If you set Implementation plan to Run on Schedule, the following options are available:
        • Run at Fixed Interval: Use a rate expression to specify an interval at which to run the command. You can specify the interval in seconds, minutes, hours, or days. This option is applicable when tasks need to be executed at a fixed interval.
          Note When you set an interval, take note of the following limits:
          • The specified interval can only be anywhere from 60 seconds to 7 days and must be longer than the timeout period of the recurring task.
          • The specified interval is the amount of time elapsed between two consecutive times that the command is run on the selected instances. This interval does not relate to the amount of time required to run the command each time. For example, assume that you set the interval to 5 minutes and that it takes 2 minutes to run the command each time. Each time the command is run, the system waits 3 minutes before it runs the command again.
          • A task is not executed immediately after the task is created. For example, assume that you set the interval to 5 minutes for a task. The task begins to be executed 5 minutes after it is created.
        • Run Only Once at Specified Time: Specify a point in time and a time zone to run the command only once.

          For example, if you set Execution Time to 2022-05-17 17:30:50 and Time Zone to (GMT+8:00) Asia/Shanghai, the command was run only once at 17:30:50 on May 17, 2022 (UTC+8).

        • Run on Clock-based Schedule: Use a cron expression to specify a schedule on which to run the command. Set Execution Frequency to a cron expression that defines a schedule accurate to the second, minute, hour, day of the month, month, day of the week, or year, and select a time zone from the Time Zone drop-down list. The system calculates the execution times of the command based on this cron expression and time zone and runs the command as scheduled. This option provides flexibility and is applicable when tasks need to executed on a regular basis. For more information about cron expressions, see Cron expression.
          Note The minimum interval must be 10 seconds or more and cannot be shorter than the timeout period of the recurring task.

          For example, if you set Execution Frequency to 0 0 12 ? * WED 2022 and set Time Zone to (GMT+8:00) Asia/Shanghai, the system runs the command at 12:00 every Wednesday in 2022 (UTC+8).

      Username The username that is used to run the command on the ECS instance.

      The best practice in permission management is to run commands based on the least privilege principle. We recommend that you run Cloud Assistant commands as a regular user. For more information, see Run Cloud Assistant commands as a regular user.

      By default, Cloud Assistant commands are run by the root user on Linux instances and by the system user on Windows instances.

    2. In the Select Instances and Select Managed Instances sections, select one or more instances.
      If you have multiple instances, you can search for instances by ID, name, or tag, and filter results by client status.
      Note A managed instance is an instance that is managed by Cloud Assistant but not provided by Alibaba Cloud. For more information, see Manage servers that are not provided by Alibaba Cloud.
  6. Click Create Task.

Procedure by using the CLI

  1. Optional:Check the state of the instances on which you want to run a command. If the instances are not in the Running (Running) state, call the StartInstance operation to start the instances.
    aliyun ecs StartInstance --InstanceId 'i-bp1f4f6o8lv0wqof****' 
    Note In this example, the values enclosed within single quotation marks ('') are example values of the parameters. You must change these values based on your actual conditions.

    For more information, see StartInstance.

  2. Optional:Call the DescribeCloudAssistantStatus operation to check whether the Cloud Assistant client is installed on the instances.
    aliyun ecs DescribeCloudAssistantStatus --RegionId 'cn-hangzhou' \
    --InstanceId.1 'i-bp1f4f6o8lv0wqof****' 
    If the value of CloudAssistantStatus is true in the response, the Cloud Assistant client is installed on the instances. Otherwise, call the InstallCloudAssistant operation to install the Cloud Assistant client on the instances. For more information, see DescribeCloudAssistantStatus and InstallCloudAssistant.
  3. Call the InvokeCommand operation to run a created 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****' \
    --Timed 'false'
    Parameter Example Description
    RegionId cn-hangzhou The region ID of the command.
    InstanceId.1 i-bp1f4f6o8lv0wqof**** The ID of the first instance on which to run the command.
    InstanceId.2 i-bp137qu6142s3mhm**** The ID of the second instance on which to run the command.
    CommandId c-hz018qp243j**** The ID of the command.
    Timed false Specifies whether to periodically run the command.

    If you want to run a command on a periodic basis, set Timed to true and set Frequency to specify a schedule on which to run the command. You can configure a command to run at a fixed interval based on a rate expression, run only once at a specified time, or run at scheduled times based on a cron expression. For example, if you specify a cron expression of 0 */20 * * * ?, the command is run every 20 minutes. For more information, see Cron expression

    For more information, see InvokeCommand.