nodejs exec问题
发布于 1年前 作者 junxing1025 1589 次浏览

我使用sudo node运行node代码, 运行到 var exec = require(‘child_process’).exec; cmd = ‘/home/usr/script/setup.sh’ exec(cmd, function callback(error, stdout, stderr) { console.log(stdout);
}); 运行不下去,但是我直接在终端运行cmd就可以,为什么啊,求助

5 回复

console.log(error, stdout,stderr);

全部打印出来看看

  1. 打印出来就是没有运行成功,我估计可能是因为脚本的原因

  2. 我使用了expect 提示没有连接成功 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is 8f:7a:50:a5:0a:4c:cf:cd:51:55:2a:80:2d:35:7e:b7. Please contact your system administrator. Add correct host key in /root/.ssh/known_hosts to get rid of this message. Offending RSA key in /root/.ssh/known_hosts:1 remove with: ssh-keygen -f “/root/.ssh/known_hosts” -R 192.168.1.1 RSA host key for 192.168.1.1 has changed and you have requested strict checking. Host key verification failed. lost connection

  3. 运行node不使用sudo 就可以运行成功

怎么感觉是你的sh文件的问题呢? 你试试 使用sodo /home/usr/script/setup.sh 看能不能执行

是吧,sudo运行直接报错了

Add correct host key in /root/.ssh/known_hosts to get rid of this message. Offending RSA key in /root/.ssh/known_hosts:1 remove with: ssh-keygen -f “/root/.ssh/known_hosts” -R 192.168.1.1 RSA host key for 192.168.1.1 has changed and you have requested strict checking. Host key verification failed.

看你异常里说明,sodo命令会使用root权限执行程序 并且使用root的环境配置,估计你的登录用户和root用户在ssh处的配置不同 检查下吧

回到顶部