场景:
命令:
for i in `cat azuregateways.txt | awk -F "-00" {'print $1'}`; do newtoken=$(grep $i newtokens.csv | cut -d : -f2); az vm run-command invoke -g $i -n $i-00 --command-id RunShellScript --scripts """cp /home/ops/data/registrationticket.json /home/ops/data/registrationticket.json_old; sudo apt install -y jq; q --arg httpsas "$newtoken" '.OutboxAccessTicket.HttpSas=$httpsas' registrationticket.json_old > registrationticket.json; docker restart mygateway""";done
丢失的变量是 $ newtoken 。与--debug一起执行时的命令:
Command arguments: ['vm', 'run-command', 'invoke', '-g', 'ANDROIDGW', '-n', 'ANDROIDGW-00', '--command-id', 'RunShellScript', '--scripts', "cp /home/ops/data/registrationticket.json /home/ops/data/registrationticket.json_old; jq --arg httpsas 'ASDASD ASD ASD ASD ASD' '.OutboxAccessTicket.HttpSas=' /home/ops/data/registrationticket.json_old > /home/ops/data/registrationticket.json", '--debug']
因此,如果我们查看一下Comnmand参数部分,我们会注意到AZ CLI丢失了jq变量:
jq --arg httpsas'ASDASD ASD ASD ASD ASD''.OutboxAccessTicket.HttpSas ='
我尝试将变量导出为全局变量,以各种可能的方式引用,执行脚本并运行该脚本,但是当我将标记作为变量引入时,它们的行为相同。
答案 0 :(得分:0)
已经联系过Azure支持,他们建议使用字典来传递参数,因为az cli毕竟在后端运行py:
az vm run-command invoke -g $RGROUP -n $RGROUP-00 --command-id RunShellScript --scripts 'echo "$1" "$2"' --parameters "hello" "'this is just a test'"
{
"value": [
{
"code": "ProvisioningState/succeeded",
"displayStatus": "Provisioning succeeded",
"level": "Info",
"message": "Enable succeeded: \n[stdout]\nhello this is just a test\n\n[stderr]\n",
"time": null
}
]
}