【发布时间】:2016-10-15 08:54:07
【问题描述】:
我无法在 nodejs 中使用 simple-ssh 模块 .exec() 执行 hive -e 命令。
我认为单引号/双引号' 或" 有问题。我不知道要按什么顺序引用哪个引号。我尝试了很多组合,但都没有奏效。
下面是代码:
var runSSH(obj){
var ssh = new SSH({
host: remote1,
user: 'root',
timeout: 1500000,
key: require('fs').readFileSync("C:/Users/Aiman/Desktop/hRep_prv"),
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
});
ssh.exec('timeout 900 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "hive -e \'select * from table_name limit 3;\'" done\' ',{
out: function(stdout) {
devHive_check += stdout;
obj.devHive_check = devHive_check;
console.log(stdout);
}
}) //-->not executing
.exec('timeout 300 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "ps -ef | grep HiveServer2"; done;\' ',{
out: function(stdout) {
devHS2_check += stdout;
obj.devHS2_check = devHS2_check;
console.log(stdout);
}
})//-->running fine
.exec('echo "parse and save"',{
out: function(){
parseData(obj);
ssh.end();
}
}).start(); //-->running fine
}
我正在登录 remoteHost1,运行几个 shell 脚本(运行良好),然后我对 remoteHost2 执行ssh 以检查Hive(hive 在 remote3 和 remote4 上运行)。HiveServer2 运行良好,但 Hive 不是。
请帮帮我。
【问题讨论】:
-
您是否尝试在实际查询 (
select * from table_name limit 3;) 周围使用转义双引号而不是转义单引号? -
是的。它仍然无法正常工作。 .exec('timeout 900 ssh -i '+rsaPath+' '+healthDevHost+' \'for i in '+hiveStageNodes+'; do clush -w ${i} "hive -e \"select * from base.merlin_tag limit 3\ ""; 完成;\' ')
-
哦,抱歉,我的意思是双引号 (
\\")。否则服务器会看到这样的命令:timeout 900 ssh -i /foo.key foo.bar.baz 'for i in foo; do clush -w ${i} "hive -e "select * from base.merlin_tag limit 3""; done;'
标签: node.js shell unix ssh npm