模糊重定向错误:远程执行命令

时间:2017-08-18 11:27:07

标签: linux shell

我正在尝试远程执行命令。该命令在本地服务器上正常工作。但是,当远程运行时,它会抱怨模糊的重定向。你能帮我解决一下吗?

该命令在本地运行正常,如下所示:

    echo '{"service": {"name": "$service", "port":443, "check":{"script":"curl '"$NODE_IP:443"' >/dev/null 2>&1","interval":"10s"}}}' | tee /etc/module/test.json

我将上述命令存储在变量

    command="echo '{"service": {"name": "$service", "port":443, "check":{"script":"curl '"$NODE_IP:443"' >/dev/null 2>&1","interval":"10s"}}}' | tee /etc/module/test.json"

然后执行它:

    remoteExecute $remotehost $command
  • remoteExecute是我们编写的一个函数。

1 个答案:

答案 0 :(得分:0)

引用有一些问题。

command="echo '{"service": {"name": "$service", "port":443, "check":{"script":"curl '"$NODE_IP:443"' >/dev/null 2>&1","interval":"10s"}}}' | tee /etc/module/test.json"

请尝试以下

command='echo '\''{"service": {"name": "$service", "port":443, "check":{"script":"curl '\''"$NODE_IP:443"'\'' >/dev/null 2>&1","interval":"10s"}}}'\'' | tee /etc/module/test.json'

将它放在脚本中并回显它会显示命令变量保存你想要的内容。

#!/bin/bash
command='echo '\''{"service": {"name": "$service", "port":443, "check":{"script":"curl '\''"$NODE_IP:443"'\'' >/dev/null 2>&1","interval":"10s"}}}'\'' | tee /etc/module/test.json'
echo "$command"

linux:~/Tst> ./test.sh 
echo '{"service": {"name": "$service", "port":443, "check":{"script":"curl '"$NODE_IP:443"' >/dev/null 2>&1","interval":"10s"}}}' | tee /etc/module/test.json