You're running jq
on the local machine, since you're using an “unquoted” here document, where the characters \`$
are interpolated. To run the command in the remote shell, arrange for the text passed in the here document to contain the command. Since you don't use any local variable or command substitution, the easiest way to do that is to use a literal here document.
ssh -i manu_bp.pem [email protected] <<'EOF'
sudo -s
cat /opt/revsw-config/apache/rijomon2_revsw_net/ui-config.json > r1.txt
echo "$(jq ".rev_component_co.mode" r1.txt)"
EOF
I assume that using backquotes around dollar-parenthesis was a mistake — that would take the output of the jq
command and use that output in turn as a command to execute.
You can simplify this: echo "$(somecommand)"
is a convoluted way of printing the output of somecommand
(with a few differences, such as stripping off final newlines and in some shells doing backslash expansion, but if these matter at all then using echo
is probably the wrong method).
ssh -i manu_bp.pem [email protected] <<'EOF'
sudo -s
cat /opt/revsw-config/apache/rijomon2_revsw_net/ui-config.json > r1.txt
jq ".rev_component_co.mode" r1.txt
EOF
You could just write this in one command (newlines optional), but beware that you need two levels of quoting, one for the local shell and one for the remove shell.
ssh -i manu_bp.pem [email protected] 'sudo sh -c "
cat /opt/revsw-config/apache/rijomon2_revsw_net/ui-config.json > r1.txt;
jq .rev_component_co.mode r1.txt"'
If you don't need to run jq
as root, only to read the file as root, use
ssh -i manu_bp.pem [email protected] '
sudo cat /opt/revsw-config/apache/rijomon2_revsw_net/ui-config.json > r1.txt;
jq .rev_component_co.mode r1.txt'
$(jq ".rev_component_co.mode" r1.txt)
means: run jq ".rev_component_co.mode" r1.txt , then run the result, then echo it. This is not what you want I guess.