简体   繁体   English

如何 SSH 一个 curl 命令

[英]How to SSH a curl command

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

Situation:情况:
SystemA=No internet. SystemA=没有互联网。 SystemB=Yes internet. SystemB=是的互联网。
SystemA has a log file. SystemA 有一个日志文件。 SystemA wants SystemB to send a curl command for him. SystemA 希望 SystemB 为他发送 curl 命令。

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

SystemB$系统B$
curl -X POST -H "Content-type: application/json" -d "$data" $hook = success curl -X POST -H "Content-type: application/json" -d "$data" $hook = 成功

How do I achieve this without SystemA 'scp'ing the log file to SystemB?在没有 SystemA 将日志文件“scp”到 SystemB 的情况下,如何实现这一点?
It's heavily schedule related so I want SystemA let SystemB work.它与日程安排密切相关,所以我希望 SystemA 让 SystemB 工作。


EDIT: I narrowed down the problem:编辑:我缩小了问题范围:

On SystemB:在系统 B 上:

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

So when I type in SystemA所以当我输入 SystemA
ssh SystemB curl -X POST -H "Content-type: application/json" -d "{$data}" $hookurl
It actually runs with -d {$data} on SystemB.它实际上在 SystemB 上使用-d {$data}运行。 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确实有效并实际将数据发送到 url,但curl: (6) Could not resolve host: application; Unknown error curl: (6) Could not resolve host: application; Unknown error occurred again.再次发生curl: (6) Could not resolve host: application; Unknown error

Use sshfs perhaps也许使用 sshfs

on systemB在系统 B 上

sshfs -p'ssh port' -o password_stdin user@systemA:/home/user/dir /home/user/dir <<< 'passwd' sshfs -p'ssh port' -o password_stdin user@systemA:/home/user/dir /home/user/dir <<< 'passwd'

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从 SystemA 获取变量定义并将它们传递给 SystemB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM