azure - 需要了解通过 REST API 在 Azure 中运行命令

标签 azure azure-virtual-machine azure-rest-api

我正在遵循此文档并尝试使用它在虚拟机中运行一个简单的 shell 脚本。

https://learn.microsoft.com/en-us/rest/api/compute/virtual%20machines%20run%20commands/runcommand#runcommandinputparameter

但是post请求的body内容需要是什么还不清楚。 commandID 可以是 RunShellScript,但我们在哪里提供脚本值。

我尝试过这样的 body

{
    commandId: "RunShellScript",
        script: "/path/scriptname"
}

还有其他选项

script: 'scriptname'
script: 'sh scriptname'

和其他结果分别导致

{
"error": {
"code": "BadRequest",
"message": "Error converting value "/home/admin1/quick-python-test.sh" to type 'System.Collections.Generic.List`1[System.String]'. Path 'script', line 3, position 52.",
"target": "runCommandInput.script"
}
}

谁能帮我正确地做这件事吗?我是 Azure 新手。

最佳答案

要通过 Azure REST API 在虚拟机中运行 bash 脚本,以下是请求的示例正文:

{
  "commandId": "RunShellScript",
  "script": [
    "echo $arg1 $arg2"
  ],
  "parameters": [
    {
      "name": "arg1",
      "value": "hello"
    },
    {
      "name": "arg2",
      "value": "world"
    }
  ]
}

关于azure - 需要了解通过 REST API 在 Azure 中运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58123330/

相关文章:

node.js - 无法从本地托管的 Node.js 应用程序连接到 AWS DB

azure - 如何获取与给定应用程序 ID 相关的 Azure PID(对象 ID)

azure - 创建 Azure DPS 时是否有任何 REST API 可以以编程方式链接 IoT 中心?

c# - 如何使用 REST API 筛选 AppInsights 自定义指标

azure - Azure 灾难恢复的替代方法

azure - 是否可以更改 Azure 临时存储驱动器的驱动器号?

azure - 如何解释 Azure 价目表 API 中包含的数量?

json - 从 Azure SQL 中非常嵌套的 JSON 中提取数据

spring - 在 Spring 应用程序中更新 Azure 总线上的消息锁定

azure - 如何使用 16GB 内存创建 Windows 虚拟机