Closed asheikm closed 4 years ago
@asheikm This should have worked. This is sample code you could try
var SSH2Promise = require('ssh2-promise');
var sshconfig = {
host: 'localhost',
username: 'sanket',
password: 'sanket',
port: 8331
}
var ssh = new SSH2Promise(sshconfig);
(async function () {
try {
const data = await ssh.exec("apk --help");
console.log("resp: ", data);
} catch (e) {
console.log("Error - " + e);
}
})();
@sanketbajoria Thanks for the reply , I am on CentOS and i have to install a package through ssh. I tried the above code with command "yum install salt-minion" ,still the issue persists. Code is not in js but TS.
@sanketbajoria , it worked, made a mistake of written an an (async function () {}); inside an another another async function, removed the additional asycnc call solved this issue
I am trying to execute command yum install on a remote linux server using ssh2-promise package, But I could not get the command response back for further processing and validation.
I have tried the following,
// Node:33528) UnhandledPromiseRejectionWarning: Unhandled promise rejection. (async function(){ try { const data = await this.ssh.exec("yum repolist all"); console.log("resp: ", data); } catch(e) { console.log(e) } })(); // This fails
I tried with proper try catch block as well, still throws unhandledPromise Exception. Can someone help me figure this out?