我需要帮助在一台机器上与nodeJs建立ssh连接,我需要在登录"sudo /usr/bin/rootsh -i -u root“之后首先使用这个命令,然后沿着这个路径"cd .”+ "cd u 01/script/“+ "cat output.txt”只会出错。
connect = require("ssh2-connect");
exec = require("ssh2-exec");
connect(
{
host: "XX.XX.XXX.XX",
username: "XXXXXXXX",
password: "XXXXX",
},
function (err, ssh) {
child = exec(
{
command:
"ssh -qtt username@host -- sudo /usr/bin/rootsh -i -u root; cd ..; cd u01/scripts/; cat saida.txt",
ssh: ssh,
},
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
console.log(err);
}
);
}
);发布于 2021-06-15 18:11:19
啊,真灵
var host = {
server: {
host: "XX.XX.XXX.XX",
username: "XXXXXXXX",
password: "XXXXX",
},
commands: [
"sudo /usr/bin/rootsh -i -u root",
"cd ..; cd u01/scripts/; cat saida.txt",
],
};
var SSH2Shell = require("ssh2shell"),
SSH = new SSH2Shell(host),
callback = function (sessionText) {
console.log(sessionText);
};
SSH.connect(callback);https://stackoverflow.com/questions/67991126
复制相似问题