我無法使用nodejs中的simple-ssh模塊.exec()
執行hive -e
命令。
我認爲單/雙引號'
或"
存在問題。我不知道按什麼順序放入哪個報價。我嘗試了很多組合,但都沒有工作。
這裏是下面的代碼:無法使用simple-ssh npm模塊的.exec()方法執行「hive -e'select * from table」
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腳本(這是運行過程中出現細微)的,然後我做一個ssh
到remoteHost2檢查Hive
(配置單元上運行遙控器3和遙控器4)。
HiveServer2
運行正常,但Hive
不是。
請幫幫我。
你是否試過在實際查詢周圍使用轉義雙引號而不是轉義單引號('select * from table_name limit 3;')? – mscdex
是的。它仍然沒有工作。 .exec('timeout 900 ssh -i'+ rsaPath +''+ healthDevHost +'\'for i in'+ hiveStageNodes +'; do clush -w $ {i}「hive -e \」select * from base.merlin_tag limit 3 \ 「」; done;') – aiman
對不起,我的意思是雙引號('\\「'),否則服務器會看到如下命令:'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;'' – mscdex