You need to enable JavaScript to run this app.
文档中心
云服务器

云服务器

复制全文
下载 pdf
云助手
RunCommand - 执行命令
复制全文
下载 pdf
RunCommand - 执行命令
调用RunCommand接口,使用手工输入命令的方式创建任务。​
使用说明​
  • 不同于通过CreateCommand接口创建自定义命令和InvokeCommand执行已有命令,RunCommand接口支持在一次调用中完成命令的创建与执行。​
  • 可通过ParameterDefinitions.N.xxx参数在命令中配置自定义参数,使用规则如下:​
  • 参数 - N:表示自定义参数的序号,取值范围:1~60。​
  • 多个自定义参数之间用&分隔。​
调试​
API Explorer
您可以通过 API Explorer 在线发起调用,无需关注签名生成过程,快速获取调用结果。
​
请求参数​
下方仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。​
Action string 必选 示例值:RunCommand​
要执行的操作,取值:RunCommand。​
​
Version string 必选 示例值:2020-04-01​
API的版本,取值:2020-04-01。​
​
WindowsPassword string 可选 示例值:-​
自定义windows用户的密码​
​
Type string 必选 示例值:Shell​
命令的类型。取值:​
  • Shell:表示创建一个在Linux实例中运行的Shell脚本。​
  • Python:表示创建一个Python脚本。​
  • Bat:表示创建一个Bat脚本。​
  • PowerShell:表示创建一个PowerShell脚本。​
​
ContentEncoding string 可选 示例值:Base64​
命令内容是否经过Base64编码处理。取值:​
  • Base64(默认):经过Base64编码处理。​
  • PlainText: 未进行编码处理。​
​
CommandContent string 必选 示例值:IyEvYm****aW9uIHN1Y2Nlc3MhIg%3D%3D​
命令内容。​
说明​
  • 请确保编码前的脚本,首行指定了脚本解释器。规则如下:​
  • Shell脚本:首行需为#!/bin/bash。​
  • Python脚本:首行需为#!/usr/bin/python。​
  • 命令内容不能超过16KB。​
​
WorkingDir string 可选 示例值:/home​
创建的命令在ECS实例中运行的目录。Linux实例默认为/home。​
​
Username string 可选 示例值:root​
执行命令时的用户名。​
​
默认值:root。​
​
Timeout integer 可选 示例值:60​
创建的命令在ECS实例中执行时最大的超时时间,单位为秒。​
  • 取值范围:30 ~ 86400。​
  • 默认值:60。​
说明​
超时后,会强制终止命令进程。​
​
InvocationName string 必选 示例值:test​
作业名称。需符合如下规则:​
  • 不超过64个字符。​
  • 只能包含中文、字母、数字、下划线“_”、中划线“-”、且不能以数字,中划线开头。​
  • 同地域下作业名称可重复。​
​
InvocationDescription string 可选 示例值:description​
作业描述,默认为空字符串,不超过256个字符。​
​
InstanceIds.N string[] 必选 示例值:InstanceIds.1=i-ervasv*****&InstanceIds.2=i-uihrdgh*****​
实例ID列表,最多支持200个ID。您可以调用DescribeInstances接口查询获取实例ID。​
  • 参数 - N:表示实例的序号。​
  • 多个Instance ID之间用&分隔。​
说明​
若指定了多台实例,但其中存在实例不满足执行条件时(例如:实例处于关机等不可用状态),都需要重新指定。​
​
RepeatMode string 可选 示例值:Rate​
设置命令执行的方式。取值:​
  • Once:默认,表示立即执行作业。​
  • Rate:周期执行作业,需要通过Frequency参数传入Rate表达式指定执行周期。​
  • Fixed:定时执行作业,需要通过LaunchTime参数指定的执行时间。​
​
Frequency string 可选 示例值:5m​
执行频率。仅RepeatMode=Rate时本参数必填。请按如下格式传入Rate表达式指定执行周期:​
  • <执行间隔数值><执行间隔单位>​
  • 执行间隔单位:支持分钟(m)、小时(h)和天(d),适用于在固定时间间隔执行作业的场景。​
  • 时间间隔数值范围:5~60(分钟),1~24(小时),1~7(天),且间隔需大于作业的超时时间。​
  • 执行间隔基于固定频率,与作业实际执行需要的时间无关。​
  • 创建作业后基于LaunchTime执行一次,根据间隔设置确定下一次执行时间。​
​
LaunchTime string 可选 示例值:2022-11-07T11:49:13Z​
执行时间。​
  • RepeatMode=Rate时,需按如下格式传入作业首次执行时间:​
  • 时间格式:RFC3339,例如:2022-11-07T11:49:13Z。​
  • RepeatMode=Fixed时,需按如下格式传入作业开始执行时间:​
  • 时间格式:RFC3339,例如:2022-11-07T11:49:13Z。​
​
RecurrenceEndTime string 可选 示例值:2022-11-07T11:49:13Z​
周期结束时间,RFC3339 格式。​
说明​
仅RepeatMode为Rate(周期执行作业)时需填写。​
​
EnableParameter boolean 可选 示例值:false​
创建的命令是否使用自定义参数。取值:​
  • false:默认,表示不使用自定义参数。​
  • true:表示使用自定义参数。​
​
ParameterDefinitions.N.Name string[] 可选 示例值:ParameterDefinitions.1.Name=dir​
自定义参数名称,需要在脚本中通过{{Param}}定义 。命名规则:​
  • 单个参数名不能超过64字节。​
  • 遵循Shell变量命名规则,a-zA-Z0-9-_的组合。首个字符不能以数字开头。中间不能有空格,可以使用下划线。​
​
ParameterDefinitions.N.Type string[] 可选 示例值:ParameterDefinitions.1.Type=String​
自定义参数类型。取值:​
  • String:表示自定义参数类型为String(字符串)类型。​
  • Digit:表示自定义参数类型为Digit(数值)类型。​
​
ParameterDefinitions.N.Required boolean[] 可选 示例值:ParameterDefinitions.1.Required=true​
自定义参数是否必填。取值:​
  • true:必填。​
  • false:非必填。​
说明​
必填时,需在Parameters参数中传入自定义参数值。​
​
ParameterDefinitions.N.DefaultValue string[] 可选 示例值:ParameterDefinitions.1.DefaultValue=ecs​
自定义参数默认值。​
说明​
请根据Type参数指定的参数类型,填写相应类型的默认值。​
​
ParameterDefinitions.N.MinLength string[] 可选 示例值:ParameterDefinitions.1.MinLength=1​
自定义参数值(字符串)的最小长度。​
说明​
  • MinLength取值范围:1~1000。​
  • Type=String时必填,且Required参数为true时默认为1。​
  • 本参数值需小于MaxLength。​
​
ParameterDefinitions.N.MaxLength string[] 可选 示例值:ParameterDefinitions.1.MaxLength=98​
自定义参数值(字符串)的最大长度。​
说明​
  • MaxLength取值范围:1~1000。​
  • Type=String时必填,且Required参数为true时默认为1000。​
  • 本参数值需大于MinLength。​
​
ParameterDefinitions.N.MinValue string[] 可选 示例值:ParameterDefinitions.1.MinValue=1​
自定义参数值(数值)的最小值。​
说明​
  • MinValue取值范围:-1000000~1000000。​
  • Type=Digit时必填,且Required参数为true时默认为-1000000。​
  • 本参数值需小于MaxValue。​
​
ParameterDefinitions.N.MaxValue string[] 可选 示例值:ParameterDefinitions.1.MaxValue=100​
自定义参数值(数值)的最大值。​
说明​
  • MaxValue取值范围:-1000000~1000000。​
  • Type=Digit时必填,且Required参数为true时默认为1000000。​
  • 本参数值需小于MinValue。​
​
ParameterDefinitions.N.DecimalPrecision string[] 可选 示例值:ParameterDefinitions.1.DecimalPrecision=4​
自定义参数值(数值)允许的小数点后位数。​
说明​
  • DecimalPrecision取值范围:0~10。​
  • Type=Digit时必填,且Required参数为true时默认为0。​
​
Parameters string 可选 示例值:{"username":"root"}​
命令中包含自定义参数时,需通过本参数传入自定义参数的键值对。 例如:命令内容为echo {{name}},则可以通过Parameter参数传入键值对{"name":"Jack"}。自定义参数将自动替换变量值name,得到一条新的命令,实际执行的是echo Jack。​
​
自定义参数规则如下:​
  • 自定义参数个数范围为0~60。​
  • Key不允许为空字符串,最多支持64个字符。​
  • Value允许为空字符串。​
  • 自定义参数与原始命令内容在Base64编码后,综合长度不能超过16KB。​
  • 设置的自定义参数名集合必须为创建命令时定义的参数集的子集。对于未传入的参数,使用默认值代替。​
​
ProjectName string 可选 示例值:default​
资源所属项目,一个资源只能归属于一个项目。​
​
Tags.N.Value string[] 可选 示例值:Tags.1.Value=v1&Tags.2.Value=v2​
用户标签的标签值。​
  • 参数 - N:表示标签值的序号,取值范围:1~20。​
  • 多个标签值之间用&分隔。​
命名规则如下:​
  • 只能包含语言字符、数字、空格和英文符号“_”、“.”、“:”、“/”、“=”、“+”、“-”、“@”。​
  • 允许为空,长度限制在0~256个字符之间。​
说明​
如果传入该参数,则必须先传入Tags.N.Key。​
​
Tags.N.Key string[] 可选 示例值:Tags.1.Key=k1&Tags.2.Key=k2​
用户标签的标签键。​
  • 参数 - N:表示标签键的序号,取值范围:1~20。​
  • 多个标签键之间用&分隔。​
命名规则如下:​
  • 不能以volc:或sys:的任意大小写组合开头。​
  • 只能包含语言字符、数字、空格和英文符号“_”、“.”、“:”、“/”、“=”、“+”、“-”、“@”。​
  • 长度限制在1~128个字符之间。​
说明​
同一资源的标签键不允许重复。​
​
​
​
返回参数​
下方仅列出本接口特有的返回参数。更多信息请参见返回结构。​
InvocationId string 示例值:ivk-2a74****​
任务执行 ID。​
​
​
​
请求示例​
​
GET /?Action=RunCommand&Version=2020-04-01&Type=Shell&InvocationName=test&InstanceIds.1=i-ydgglud*****&CommandContent=ls&ContentEncoding=PlainText HTTP/1.1​
Host: ecs.cn-beijing.volcengineapi.com​
Region: cn-beijing​
Service: ecs​
​
返回示例​
​
{​
"ResponseMetadata":{​
"RequestId":"2023082515303301022514515207C4****",​
"Action":"RunCommand",​
"Version":"2020-04-01",​
"Service":"ecs",​
"Region":"cn-beijing"​
},​
"Result":{​
"InvocationId":"iv-fdkzoqkdl*****"​
}​
}​
​
错误码​
下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。​
​
状态码​
错误码​
错误信息​
说明​
400​
InvalidParameterDefinitionName.Malformed​
The specified ParameterDefinition Name is malformed. The name can contain only lowercase letters (a to z), uppercase letters (A to Z), numbers (0 to 9), and underscores (_).​
自定义参数名格式错误:仅支持a-zA-Z0-9_的组合,首个字符不能以数字开头。​
400​
InvalidParameterDefinitionType.Malformed​
The specified ParameterDefinition Type is malformed.​
自定义参数类型不合法。​
400​
MissingParameter.ParameterDefinitionName​
The required parameter ParameterDefinitionName is not supplied.​
自定义参数名不能为空。​
400​
LimitExceeded.MaximumParameterDefinitionName​
The specified ParameterDefinitionName exceeds the limit.​
指定的自定义参数名长度超出限制。​
400​
MissingParameter.ParameterDefinitions​
The required parameter ParameterDefinitions is not supplied.​
参数定义不能为空。​
400​
LimitExceeded.MaximumInstanceIds​
The specified InstanceIds exceeds the limit.​
实例数量超出限制。​
400​
MissingParameter.InstanceIds​
The required parameter InstanceIds is not supplied.​
实例 ID 不能为空。​
400​
LimitExceeded.MaximumInvocationDescription​
The specified InvocationDescription exceeds the limit.​
指定的作业描述长度超出限制。​
400​
InvalidInvocationName.Malformed​
The specified InvocationName is malformed.​
指定的作业名称不合法。​
400​
MissingParameter.CommandContent​
The required parameter CommandContent is not supplied.​
命令内容不能为空。​
400​
LimitExceeded.MaximumInvocations​
The running invocations exceed the limit.​
执行中的作业数量超出限制。​
400​
LimitExceeded.Tags​
You've reached the limit on the number of Tags that you can create.​
已达到可创建的标签数量上限。​
400​
InvalidProjects.ListFailed​
Fail to list projects.​
获取项目失败。​
400​
InvalidBase64Content.Malformed​
The specified Base64 Content is malformed.​
指定的Base64内容不合法。​
400​
LimitExceeded.MaximumParameterDefinitions​
The specified ParameterDefinitions exceeds the limit.​
指定的自定义参数定义个数超出限制。​
400​
InvalidFrequency.Malformed​
The specified Frequency is malformed.​
周期执行规则表达式非法。​
400​
MissingParameter.Frequency​
The required Frequency is not supplied.​
周期执行规则表达式不能为空。​
400​
InvalidRecurrenceEndTime.Malformed​
The specified RecurrenceEndTime is malformed.​
周期结束时间非法。​
400​
MissingParameter.RecurrenceEndTime​
The required RecurrenceEndTime is not supplied.​
周期结束时间不能为空。​
400​
InvalidLaunchTime.Malformed​
The specified LaunchTime is malformed.​
指定的执行时间不合法。​
400​
MissingParameter.LaunchTime​
The required LaunchTime is not supplied.​
执行时间不能为空。​
400​
InvalidInstanceId.Unregister​
The specified instance is unregister.​
指定的实例未注册 Agent。​
400​
InvalidCloudAssistantStatus.Malformed​
The cloud assistant status of the instance cannot be operated.​
当前实例Agent的状态不支持该操作。​
400​
InvalidRepeatMode.Malformed​
The specified RepeatMode is malformed.​
指定的命令执行方式不合法。​
400​
InvalidParameters.Malformed​
The specified Parameters are malformed.​
指定的自定义参数不合法。​
400​
InvalidParameterDefinitions.Malformed​
The specified ParameterDefinitions is malformed.​
指定的参数定义不合法。​
400​
LimitExceeded.MaximumCommandContent​
The specified CommandContent exceeds the limit.​
指定的命令内容长度超出限制。​
400​
MissingParameter.AccountId​
The required parameter AccountId is not supplied.​
用户ID不能为空。​
400​
InvalidTagKey.Malformed​
The specified TagKey is malformed.​
指定的标签键不合法。​
400​
InvalidTagValue.Malformed​
The specified TagValue is malformed.​
指定的标签值不合法。​
400​
InvalidEnableParameter.Malformed​
The specified EnableParameter is malformed.​
指定的是否启用参数不合法。​
400​
MissingParameter.Type​
The required parameter Type is not supplied.​
命令类型不能为空。​
400​
LimitExceeded.MaximumParameters​
The specified Parameters exceeds the limit.​
指定的自定义参数个数超出限制。​
400​
MissingParameter.ParameterName​
The required Parameters Name is not supplied.​
参数名不能为空。​
400​
LimitExceeded.MaximumParameterName​
The specified Parameter Name exceeds the limit.​
指定的自定义参数名长度超出限制。​
400​
InvalidType.Malformed​
The specified Type is malformed.​
指定的命令类型不合法。​
400​
LimitExceeded.MaximumTimeout​
The specified timeout exceeds the limit.​
指定的超时时间(s)超出限制。​
400​
LimitExceeded.MaximumInvocationName​
The specified InvocationName exceeds the limit.​
指定的作业名称长度超出限制。​
404​
InvalidParameterDefinitions.NotFound​
The specified ParameterDefinitions does not exist.​
指定的自定义参数未定义。​
404​
InvalidProject.NotFound​
The specified Project does not exist.​
指定的项目不存在。​
404​
MissingParameter.Tags​
The required parameter Tags are empty.​
标签参数不能为空。​
409​
InvalidParameterDefinitions.Conflict​
The specified ParameterDefinition already exists.​
指定的自定义参数已存在。​
409​
InvalidInstanceIds.Conflict​
The specified InstanceId already exists.​
指定实例 ID 重复。​
409​
InvalidTagKey.Conflict​
The specified TagKey already exists.​
指定的标签键已存在。​
500​
InternalError​
An internal error has occurred.​
内部错误,请重试。如果多次尝试失败,请提交工单。​
​
​
最近更新时间:2026.01.08 16:54:44
这个页面对您有帮助吗?
有用
有用
无用
无用