Run shell script in Linux using web URL from external browser | Linux shell scripting | 2021

preview_player
Показать описание
In this video , I am showing how to Run shell script in Linux using web URL from any external browser without login into server.

Here I am using a basic node app which will link shell script located in server and web URL.so the moment you browse the URL from browser then shell script will be immediately executed and you can see status of script on browser itself.

Work flow : web URL--- Node app ---shell script

you can use this process on production environments also.

Node app code provided in comments , please copy and use if required

#PJTechWorld #shellscript #devopstutorial #Linututorial

SUBSCRIBE to the channel for more videos and if you have any queries or suggestions or requests ,please put all those in comment section.
Рекомендации по теме
Комментарии
Автор

Hi Bro
A small suggestion dont take it bad.
Please speak louder and Terminal is also

praveen
Автор

node app code :
const http = require("http");
const exec =
const path = require("path");
const async = require("async");

const projectPath = process.argv[2];
const absolutePath = path.join(projectPath);

const cmds = ["sh /root/backend.sh"].concat(process.argv.filter((arg, index) => { return index > 2; }));

const execCmds = cmds.map((cmd) => {
return function(callback) {
exec(`cd ${absolutePath} && ${cmd}`, {maxBuffer: 1024 * 600}, (err, stdout, stderr) => {
if(err) return callback(err);
callback(null, `--- ${cmd} ---:\n stdout: ${stdout} \n stderr: ${stderr}\n`);
});
};
});

const updateProject = function(callback) {
async.series(
execCmds
, function(err, results) {
if(err) return callback(err);
return callback(null, results.join(""));
});
};

http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
console.log("An event has been detected on the listened port: starting execution...")

updateProject((e, result) => {
let response = "";
if(e) {
console.error(`exec error: ${e}`);
response += `exec error: ${e}`;
}
if(result) {
console.log(result);
response += `\n ${result}`;
}
res.end(response);
});

}).listen(1337);
console.log("Git-auto-pull is running");

pjtechworld