すべてのプロダクト
Search
ドキュメントセンター

CloudOps Orchestration Service:ACS-ECS-ScheduleToRunCommand

最終更新日:Dec 21, 2025

テンプレート名

ACS-ECS-ScheduleToRunCommand:ECS インスタンスでのコマンドのバッチ実行のスケジュール

今すぐ実行

テンプレートの説明

このテンプレートは、複数の Elastic Compute Service (ECS) インスタンスでクラウドアシスタントコマンドのバッチ実行をスケジュールします。システムメンテナンスやタスクの自動化などの定期タスクに最適です。設定には、リージョン ID (regionId)、cron 式 (triggerCron)、ターゲットインスタンス (targets)、コマンドタイプ (commandType)、およびコマンド内容 (commandContent) が必要です。テンプレートの実行後、コマンド出力のリストが返され、実行ステータスを確認できます。

テンプレートタイプ

自動

所有者

Alibaba Cloud

入力パラメーター

パラメーター

説明

タイプ

必須

デフォルト値

制限

triggerEndDate

スケジュールされたタスクの終了時間。

String

はい

targets

ターゲットインスタンス

Json

はい

regionId

リージョン ID。

String

いいえ

{{ ACS::RegionId }}

triggerCron

CRON 式。

String

いいえ

0 0 12 ? * *

timeZone

タイムゾーン。

String

いいえ

UTC

commandType

Cloud Assistant コマンドのタイプ。

String

いいえ

RunShellScript

commandContent

Cloud Assistant コマンド。

String

いいえ

echo hello

コマンドの長さは最大 16,384 バイトです。

workingDir

ECS インスタンスのコマンドの作業ディレクトリ。

String

いいえ

""

timeout

タイムアウト期間 (秒)。

Number

いいえ

600

rateControl

タスク実行の同時実行数

Json

いいえ

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

CloudOps Orchestration Service (OOS) によって引き受けられる Resource Access Management (RAM) ロール。

String

いいえ

OOSServiceRole

出力パラメーター

パラメーター

説明

タイプ

commandOutputs

List

テンプレートを実行するために必要な権限ポリシー

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:GetApplicationGroup"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳細

詳細については、GitHub の ACS-ECS-ScheduleToRunCommand.yml をご参照ください。

テンプレートコンテンツ

FormatVersion: OOS-2019-06-01
Description:
  en: 'Schedule to run command on ECS instances, applicable to scenarios that require periodically running commands on multiple ECS instances, such as system maintenance and task automation. During configuration, users need to provide the following required parameter information: Region ID (regionId), which specifies the region of the ECS instances where the commands will be run, Cron Expression (triggerCron), which defines the schedule for the task, Target Instances (targets), which defines the specific ECS instances to be operated on, and Command Type (commandType) and Command Content (commandContent). Upon execution, the template will return a list of the output results of the run command, enabling users to verify the status of the command executions.'
  zh-cn: 'Schedules the batch execution of Cloud Assistant commands on multiple ECS instances. It is ideal for periodic tasks, such as system maintenance and task automation. The configuration requires the region ID (regionId), a cron expression (triggerCron), the target instances (targets), the command type (commandType), and the command content (commandContent). After the template runs, it returns a list of the command outputs to verify the execution status.'
  name-en: ACS-ECS-ScheduleToRunCommand
  name-zh-cn: Schedules batch execution of commands on ECS instances
  categories:
    - time_trigger
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: Region ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  triggerCron:
    Description:
      en: 'refer them here: https://www.alibabacloud.com/help/document_detail/169784.html'
      zh-cn: 'For more information, see https://www.alibabacloud.com/help/document_detail/169784.html'
    Label:
      en: Cronexpression
      zh-cn: cron expression
    Type: String
    AssociationProperty: Cron
    Default: 0 0 12 ? * *
  triggerEndDate:
    Description:
      en: 'Format: yyyy-MM-ddTHH:mm:ssZ.'
      zh-cn: 'Format: yyyy-MM-ddTHH:mm:ssZ'
    Label:
      en: triggerEndDate
      zh-cn: End time of the time trigger
    Type: String
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDTHH:mm:ssZ'
  timeZone:
    Label:
      en: timeZone
      zh-cn: Time zone
    Type: String
    AssociationProperty: TimeZone
    Default: UTC
  targets:
    Type: Json
    Label:
      en: TargetInstance
      zh-cn: Target instances
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: regionId
      Status: Running
  commandType:
    Label:
      en: CommandType
      zh-cn: Cloud Assistant command type
    Type: String
    AllowedValues:
      - RunBatScript
      - RunPowerShellScript
      - RunShellScript
    Default: RunShellScript
  commandContent:
    Label:
      en: CommandContent
      zh-cn: Cloud Assistant command content
    Type: String
    MaxLength: 16384
    AssociationProperty: Code
    Default: echo hello
  workingDir:
    Description:
      en: '<td class="entry colsep-1 rowsep-1">
            <p class="p">Default value: </p>
            <ul class="ul">
            <li class="li"> Linux instances: the home directory of the administrator (the root user), which is<code class="ph codeph">/root</code>.</li>
            <li class="li"> Windows instances: the directory where the Cloud Assistant client process resides,such as <code class="ph codeph">C:\Windows\System32</code>.</li>
            </ul>
          </td>'
      zh-cn: '<td class="entry colsep-1 rowsep-1">
              <p class="p">Default value:</p>
              <ul class="ul">
                <li class="li">For Linux instances, the default directory is the home directory of the administrator (root user), which is <code class="ph codeph">/root</code>.</li>
                <li class="li">For Windows instances, the default directory is where the Cloud Assistant client process is located, such as <code class="ph codeph">C:\Windows\System32</code>.</li>
              </ul>
            </td>'
    Label:
      en: WorkingDir
      zh-cn: Directory to run the command on the ECS instance
    Type: String
    Default: ''
  timeout:
    Label:
      en: Timeout (s)
      zh-cn: Timeout (s)
    Type: Number
    Default: 600
  rateControl:
    Label:
      en: RateControl
      zh-cn: Concurrency rate for task execution
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: The RAM role assumed by OOS
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: timerTrigger
    Action: ACS::TimerTrigger
    Description:
      en: Triggers a task as scheduled by specifying type and expression
      zh-cn: Triggers a task as scheduled by specifying the trigger type and expression
    Properties:
      Type: cron
      Expression: '{{ triggerCron }}'
      EndDate: '{{ triggerEndDate }}'
      TimeZone: '{{ timeZone }}'
  - Name: getInstance
    Description:
      en: Views the ECS instances
      zh-cn: Obtains ECS instances
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: runCommand
    Action: 'ACS::ECS::RunCommand'
    Description:
      en: Execute cloud assistant command
      zh-cn: Executes a Cloud Assistant command
    Properties:
      regionId: '{{ regionId }}'
      commandContent: '{{ commandContent }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
      commandType: '{{ commandType }}'
      workingDir: '{{ workingDir }}'
      timeout: '{{ timeout }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
      Outputs:
        commandOutputs:
          AggregateType: 'Fn::ListJoin'
          AggregateField: commandOutput
    Outputs:
      commandOutput:
        Type: String
        ValueSelector: invocationOutput
Outputs:
  commandOutputs:
    Type: List
    Value: '{{ runCommand.commandOutputs }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - timeZone
          - triggerCron
          - triggerEndDate
        Label:
          default:
            zh-cn: Schedule Settings
            en: Timer Trigger Configure
      - Parameters:
          - commandType
          - commandContent
          - workingDir
          - timeout
        Label:
          default:
            zh-cn: Command Execution Options
            en: run command options
      - Parameters:
          - regionId
          - targets
        Label:
          default:
            zh-cn: Select Instances
            en: Select Ecs Instances
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: Advanced Options
            en: Control Options