【问题标题】:Unable to execute "hive -e 'select * from table" using .exec() method of simple-ssh npm module无法使用 simple-ssh npm 模块的 .exec() 方法执行“hive -e 'select * from table”
【发布时间】: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


【解决方案1】:

现在解决了。
而不是hive 中的单引号,它需要双引号,即行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\' ',{
我做到了
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\' ',{,它奏效了。
感谢@mscdex 的支持。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-30
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    相关资源
    最近更新 更多