• Uncategorized

About linux : Running-jq-on-a-remote-machine-over-ssh-and-overwrite-the-file

Question Detail

I am trying to create a file from the output of jq command over ssh command.

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

It gives me following error:

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

Am I not running the command properly or is there any other problem?

Question Answer

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

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.