通过XMPP,NodeJS发送shell命令

时间:2016-10-24 11:25:14

标签: node.js shell xmpp

我已经用NodeJS和“simple-xmpp”编写了一个XMPP客户端:它等待从另一个XMPP客户端发送的消息,读取消息,如果这些是shell命令,则执行它们。

例如,如果客户端A向客户端B发送消息:“。/ run_myscript.sh”,则客户端B将运行脚本./run_myscript.sh,非常简单。

在XMPP上发送“run”效果很好(脚本启动)但是发送“stop”(杀死脚本)似乎没有效果!脚本继续运行。

为了研究这个问题,我还向客户端A添加了一个“测试”回复,以便查看整个通信是否被破坏,看起来是这样:从B到A的回复似乎没有收到! 为什么呢?

此处客户B分析收到的消息时的部分:

xmpp.on('chat', function(from, message) { 
var msg = message.toString();
if(msg === 'run'){           //if the message is "run"...
    var cmd = require('child_process').execSync('./run.sh').exec; //run the script

}else if(msg === 'stop'){    //if the message is "stop"...   
    var cmd = require('child_process').execSync('./stop.sh').exec; //it should stop it but it doesn't work!

    //Let's try with a test reply to Client A
    xmpp.send('pippoman@prova.it', 'stopped!'); //replies not sent!!!
});

0 个答案:

没有答案