Skip to content
Advertisement

How to SSH a curl command

env = GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

Situation:
SystemA=No internet. SystemB=Yes internet.
SystemA has a log file. SystemA wants SystemB to send a curl command for him.

SystemA$
ssh SystemB curl -X POST -H "Content-type: application/json" -d "$data" $hook = fail

SystemB$
curl -X POST -H "Content-type: application/json" -d "$data" $hook = success

How do I achieve this without SystemA ‘scp’ing the log file to SystemB?
It’s heavily schedule related so I want SystemA let SystemB work.


EDIT: I narrowed down the problem :

On SystemB:

curl -X POST -H "Content-type: application/json" -d '{$data}' $hookurl = success
curl -X POST -H "Content-type: application/json" -d {$data} $hookurl = fail

So when I type in SystemA
ssh SystemB curl -X POST -H "Content-type: application/json" -d "{$data}" $hookurl
It actually runs with -d {$data} on SystemB. How can I fix this?


Update:
ssh SystemB curl -X POST -H "Content-type: application/json" -d "'{$data}'" $hookurl

did work and actually sent data to url, but curl: (6) Could not resolve host: application; Unknown error occurred again.

Advertisement

Answer

You can use this command :

ssh SystemB /bin/bash <<< "$(declare -p data hook);"'curl -X POST -H "Content-type: application/json" -d "$data" "$hook"'

"$(declare -p data hook);" takes variable definitions from SystemA and passes them to SystemB

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement