【问题标题】:Running jq on a remote machine over ssh and overwrite the file通过 ssh 在远程机器上运行 jq 并覆盖文件
【发布时间】:2018-03-20 06:16:31
【问题描述】:

我正在尝试通过 ssh 命令从jq 命令的输出创建一个文件。

ssh <server-Name> "jq '.credsStore = "ecr-login"' ~/.docker/config.json > ~/.docker/output.json "

它给了我以下错误:

bash: .docker/output.json: No such file or directory

是我没有正确运行命令还是有其他问题?

【问题讨论】:

  • 对于初学者,您尝试发送的命令包含未转义的双引号...
  • 您指的是哪些引文? @JeffMercado
  • @BhavikJoshi:下面的答案对你有帮助吗?

标签: linux shell ssh jq


【解决方案1】:
ssh "$server" "bash -s" <<'EOF'
[[ -e ~/.docker/config.json ]] || {
  echo "ERROR: $HOME/.docker/config.json does not exist on the remote server" >&2
  exit 1
}

jq '.credsStore = "ecr-login"' \
  <~/.docker/config.json \
  >~/.docker/output.json 
EOF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 2019-05-02
    • 1970-01-01
    • 2013-07-06
    • 2018-10-12
    • 1970-01-01
    • 2012-09-30
    相关资源
    最近更新 更多