Skip to content

Instantly share code, notes, and snippets.

@Franco-Poveda
Created January 14, 2016 10:52
Show Gist options
  • Select an option

  • Save Franco-Poveda/9ad6705b2c71d64af7ff to your computer and use it in GitHub Desktop.

Select an option

Save Franco-Poveda/9ad6705b2c71d64af7ff to your computer and use it in GitHub Desktop.
Simple script to execute a bash command via a http request just using the node native functions
/*
* Listen incommig HTTP connection to '/'
* and executes a arbitrary command to
* the host stdout.
*
* Pogui (2016)
* poguijuaz [at] gmail
*/
var http = require('http'),
exec = require('child_process').exec;
var cmd = '<your bash command>';
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
exec(cmd, function(err, stdout, stderr) {console.log(stdout)});
res.end('OK');
}).listen(9669);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment