0

When I running jq command locally it works:

jq --arg ip "$IP" '.nodes|.app|.ip = $ip' nodes.json

Output:

{ "nodes": 1, "is_manager": true, "ip": "127.0.0.1", "cpus": 16, "memory": 64 }

But I can't figure out how do I send it remotely via ssh, for example this command returns an error:

 ssh -o StrictHostKeyChecking=no -i key.pem user@"172.13.1.23" "jq --arg ip "127.0.0.1" '.nodes|.app|.ip = $ip' nodes.json"

Output:

jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at , line 1: .nodes|.app|.ip = jq: 1 compile error

ybonda
  • 1,546
  • 25
  • 38

1 Answers1

2

$ip is in double quotes, and so is expanded locally. You need to escape the dollar sign.

ssh -o StrictHostKeyChecking=no -i key.pem user@"172.13.1.23" \
  "jq --arg ip "127.0.0.1" '.nodes|.app|.ip = \$ip' nodes.json"
chepner
  • 497,756
  • 71
  • 530
  • 681
  • What about this command: https://stackoverflow.com/questions/58428131/sending-jq-with-argjson-via-ssh – ybonda Oct 17 '19 at 12:00