-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#10 Issue -- Ssh values Iteration from the array #11
Comments
Again, this is a problem with your JavaScript, not with simple-ssh. JavaScript doesn't have block scope like other languages, it has function scope so you're replacing the value for var ssh = null;
for (var i = 0; i < succ.length; i++) {
ssh = new SSH({
host: succ[i].hostname,
port: succ[i].hostport,
user: succ[i].hostuser,
pass: succ[i].hostpassword
});
ssh.exec('nproc', {
out: function(cpucore) {
// This is asynchronous so `ssh` has been re-assigned i.e. it's the last instance of ssh
ssh.exec(...);
}
}).start();
} To get around this, you should be creating these in a separate function (I would also suggest chaining function createConnection(config) {
var ssh = new SSH({
host: config.hostname,
port: config.hostport,
user: config.hostuser,
pass: config.hostpassword
});
ssh.exec('nproc', {
out: function(cpucore) {
console.log(cpucore);
}
}).exec('cat /proc/meminfo | grep MemTotal | cut -d":" -f2| cut -d"k" -f1|tr -d " "', {
...
}).exec({
...
}).start();
}
for (var i = 0; i < succ.length; i++) {
createConnection(succ[i]);
} |
Thanks Mcluck ....its working..!!!!! |
Hi Mcluck,
Sorry to post this issue again and in the previous issue there wer some errors in the code which i have share .here is the exact code which i'm trying to do
The text was updated successfully, but these errors were encountered: