我正在使用Google Cloud CLI创建虚拟机,我还需要通过CLI创建防火墙规则;
我有一个bash脚本,带有一些预定义的变量,如端口、描述等;它创建一个VM,然后为它应用防火墙规则;
应用我使用的规则
gcloud compute firewall-rules create但是我得到的错误是GCP文档here中定义的参数
ERROR: (gcloud.compute.firewall-rules.create) unrecognized arguments:
./1541078390.sh: line 84: --allow: command not found
./1541078390.sh: line 86: --source-ranges: command not found
./1541078390.sh: line 87: --priority: command not found我尝试过不同的方法,但都是相似的方法,而且我一直在尝试。我是不是漏掉了什么?
该脚本的一个示例是
ports="udp:2555"
vm="client"
priority=100
description="Port 2555"
gcloud compute firewall-rules create "${ports%%:*} rule" \
--allow "${ports}" \ (line 84)
--source-tags "$vm" \
--source-ranges "0.0.0.0/0" \ (line 86)
--priority "$priority" \(line 87)
--description "$description" \
--direction INGRESS发布于 2018-11-01 22:40:15
我想你可能会在一些反斜杠后留出空格。请确保删除它们后面的所有空格,然后重试。
根据您的示例,在第83、85和86行应该有一个空格
干杯,
发布于 2018-11-02 00:26:26
我找到了为什么会发生这种事。
在终端中手动执行该命令后,它会输出详细的错误,其中“无法识别”的参数显然无法通过正则表达式验证。因此,我根据错误中的推荐语法调整了参数语法,并取得了效果;
TL;DR
“无法识别”的参数格式不佳;
https://stackoverflow.com/questions/53102425
复制相似问题