gpt4 book ai didi

python - 使用多个命令行参数的 az cli run-command 调用失败

转载 作者:行者123 更新时间:2023-12-02 08:02:13 25 4
gpt4 key购买 nike

我正在尝试使用命令行参数执行远程 python 脚本。 python脚本是使用argparse开发的。我们知道 argparse 接受以 -/-- 作为参数名称的输入。在 az cli 的 --parameters 中传递此参数会引发奇怪的错误。

问题如何使用 az run-command invoke

为 python 脚本传递类似 python argparse 的参数<小时/>

一些示例尝试和输出

尝试 - 1

az vm run-command invoke     --resource-group MDC_VME_DEV_EUS  \
--name ubuntumemsql002 --command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata" "-o /mnt/workspace/data/outdata" "--input_compressed_data" "--output_compressed_data" "-a 600" "-p 0.1" "-b 600 1200 1800" "-s 1543275000"

az vm run-command invoke: ' /mnt/workspace/data/outdata' is not a valid value for '--output'. See 'az vm run-command invoke --help'.

尝试 - 2

 bash-4.4# az vm run-command invoke    \
--resource-group MDC_VME_DEV_EUS \
--name ubuntumemsql002 \
--command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000"

Deployment failed. Correlation ID: 36317037-4cfb-429e-b113-f8995d3419fb. VM has reported a failure when processing extension 'RunCommandLinux'.
Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]

[stderr]
/var/lib/waagent/run-command/download/7/script.sh: 1: export: /mnt/workspace/data/indata: bad variable name

".

尝试 - 3

bash-4.4# az vm run-command invoke    \
--resource-group MDC_VME_DEV_EUS \
--name ubuntumemsql002 \
--command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000" --verbose
Deployment failed. Correlation ID: 9efaf01c-3d7b-473a-90c8-802d63b6ccf0. VM has reported a failure when processing extension 'RunCommandLinux'.
Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]

[stderr]
/var/lib/waagent/run-command/download/8/script.sh: 1: export: /mnt/workspace/data/indata: bad variable name
".

尝试 - 4

bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters -i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000
az vm run-command invoke: error: argument --parameters: expected at least one argument
usage: az vm run-command invoke [-h] [--verbose] [--debug]
[--output {json,jsonc,table,tsv,yaml}]
[--query JMESPATH]
[--resource-group RESOURCE_GROUP_NAME]
[--name NAME] --command-id COMMAND_ID
[--scripts SCRIPTS [SCRIPTS ...]]
[--parameters PARAMETERS [PARAMETERS ...]]
[--subscription _SUBSCRIPTION]
[--ids ID [ID ...]]

尝试 - 5

 bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters \-i /mnt/workspace/data/indata \-o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data \-a 600 \-p 0.1 \-b 600 1200 1800 \-s 1543275000
az vm run-command invoke: error: argument --parameters: expected at least one argument
usage: az vm run-command invoke [-h] [--verbose] [--debug]
[--output {json,jsonc,table,tsv,yaml}]
[--query JMESPATH]
[--resource-group RESOURCE_GROUP_NAME]
[--name NAME] --command-id COMMAND_ID
[--scripts SCRIPTS [SCRIPTS ...]]
[--parameters PARAMETERS [PARAMETERS ...]]
[--subscription _SUBSCRIPTION]
[--ids ID [ID ...]]
bash-4.4#

直接 VM CLI 尝试

并且,只是为了确认,当我在 CLI 中运行相同的命令时,它们可以完美执行

/mnt/workspace/scripts/test.py -i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800  -s 1543275000
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X13.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X13-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X11.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X11-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X12.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X12-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X15.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X15-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X14.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X14-data-1543275000.gz'result='Success' )
<小时/>

一些示例(如评论中建议的那样)

运行 - 1

bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters "\-i" "/mnt/workspace/data/indata" "\-o" "/mnt/workspace/data/outdata" "\--input_compressed_data" "\--output_compressed_data" "\-a" "600" "\-p" "0.1" "\-b" "600 1200 1800" "\-s" "1543275000"
Deployment failed. Correlation ID: 70f7646e-fa94-4104-8067-e42b92470803. VM has reported a failure when processing extension 'RunCommandLinux'. Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]

[stderr]
/var/lib/waagent/run-command/download/9/script.sh: 1: export: 1200: bad variable name

运行 - 2

bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/prepare_data_for_memsql_ingest.py \
> --parameters "\-i" "/mnt/workspace/data/indata" "\-o" "/mnt/workspace/data/outdata" "\--input_compressed_data" "\--output_compressed_data" "\-a" "600" "\-p" "0.1" "\-b" "600" "1200" "1800" "\-s" "1543275000"
Deployment failed. Correlation ID: e460bfa4-286e-43c3-8a60-6f74b78c7e85. VM has reported a failure when processing extension 'RunCommandLinux'. Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]

[stderr]
usage: PROG [-h] -i INPUT_DIR -o OUT_DIR
(--input_compressed_data | --input_uncompressed_data)
(--output_compressed_data | --output_uncompressed_data) -a
AGGREGATE_INTERVAL -p {<__main__.Range object at 0x7fd86f8c49d0>}
-b BACKDATE_INTERVAL_LIST [BACKDATE_INTERVAL_LIST ...] -s
START_EPOCH
PROG: error: argument -i/--input_dir is required
".
<小时/>

最佳答案

@kumar_m_kiran - 请尝试一下并让我知道它是否有效:

az vm run-command invoke     --resource-group MDC_VME_DEV_EUS  \
--name ubuntumemsql002 --command-id RunShellScript \
--scripts "python /mnt/workspace/scripts/test.py -i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000"

可能您需要在开头使用“python”关键字运行脚本。您还可以在脚本参数本身中提供脚本的所有参数。

关于python - 使用多个命令行参数的 az cli run-command 调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53588825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com