I need to show shell script report to html using node js
What I did:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var exec = require('child_process').exec;
var rexec = require('remote-exec');
var fs = require('fs');
var cmds = [
'sh /indexer.sh'
];
var connection_options = {
port: 22,
username: 'root',
privateKey: fs.readFileSync('/home/raj2/.ssh/id_rsa'),
passphrase: 'gworks.mobi',
stdout: fs.createWriteStream('./views/output.txt'),
stderr: fs.createWriteStream('./views/error.txt')
};
var hosts = [
'10.1.2.50'
];
app.post('/nodeapp', urlencodedParser, function (req, res) {
// res.send('You sent the name "' + req.body.selectpicker + '".');
//console.log( req.body.selectpicker);
//res.send('You sent the name "' + req.body.selectpicker + '".');
if (req.body.selectpicker == "reindex") {
var cmds = [
'sh /indexer.sh'
];
res.send('reindex Process Started');
rexec(hosts, cmds, connection_options, function (err, stdout, stderr) {
if (err) {
console.log(err);
res.send(req.body.err)
} else if (stdout) {
console.log('stdout!!');
res.send(req.body.stdout)
} else {
console.log('Great Success!!');
}
});
}
});
I have call remote machine to run the shell script and I print the shell report to console, but I need to show this status to front end(html).
I have write the shell report to file(output.txt) so i follow below way its not works for me.
fs.readFile('./views/output.txt', function (err, html) {
if (err) {
throw err;
}
http.createServer(function (request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
});
});
Suggest me How to show shell report to html using nodejs or Any other best way to do this.
via Rajkumar .E
No comments:
Post a Comment