【问题标题】:aws ssm send-command not working with special charactersaws ssm 发送命令不适用于特殊字符
【发布时间】:2021-03-06 01:55:45
【问题描述】:

我能够向我的一些 Amazon ec2 实例发送简单的命令。例如:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","mkdir -p test"]
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","sudo chmod 777 test"]

我还可以将文本回显到示例文件:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","echo thisvalue = temp >> test/sample.txt"]

但是,如果我使用括号作为命令/文本的一部分,例如:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","echo [default] > test/sample.txt"]

我收到以下错误:

解析参数“--parameters”时出错:预期:“,”,接收到:“>”用于输入:

当文本被括在括号 [] 中时,就会引发问题。因此,问题归结为:如何通过 aws ssm send-command 函数传递“特殊”字符?

【问题讨论】:

  • 是否可以尝试使用反斜杠转义特殊字符?
  • 如果我这样做:[\default 这可行,但只给我 [default(没有右括号)。但是,如果我这样做 [\default]\ 它根本不起作用。
  • 试试\[default\]
  • 与原帖相同的问题。

标签: amazon-web-services amazon-ec2


【解决方案1】:

解决办法是:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands='["cd /home/ec2-user","echo [\default\] > test/sample.txt"]'

换句话说,在命令选项周围加上单引号并正确转义括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2021-05-26
    • 2018-04-10
    • 2014-08-09
    • 2016-03-03
    • 1970-01-01
    相关资源
    最近更新 更多