I'm looking for a way to SSH into a virtual machine and then execute certain scripts inside the virtual machine using Node.js
So far I've created the shell script that automate the login to the virtual machine but i'm unable to figure out how to move forward.
My shell script for login to remote server
spawn ssh root@localhost
expect "password"
send "123456"
send "\r"
interact
This is my server.js
var http = require('http');
var execProcess = require("./exec_process.js");
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
execProcess.result("sh sshpass.sh", function(err, response){
if(!err){
res.end(response);
}else {
res.end("Error: ", err);
}
});
}).listen(3000);
console.log('Server listening on port 3000');
exec_process.js
var exec = require('child_process').exec;
var result = function(command, cb){
var child = exec(command, function(err, stdout, stderr){
if(err != null){
return cb(new Error(err), null);
}else if(typeof(stderr) != "string"){
return cb(new Error(stderr), null);
}else{
return cb(null, stdout);
}
});
}
exports.result = result;
Any help is appreciated thanks
node server.jsError: