我正在尝试远程执行命令。该命令在本地服务器上正常工作。但是,当远程运行时,它会抱怨模糊的重定向。你能帮我解决一下吗?
该命令在本地运行正常,如下所示:
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
答案 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