我正在遵循此文档并尝试使用它在虚拟机中运行一个简单的 shell 脚本。
但是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/