NodeJS

Execute remote bash script

Execute bash script (*.sh) on remote server, white remote-exec module.

Nodejs

Install remote-exec module

npm i remote-exec --save-dev

Add server ip, username and password for the server SSH connection, and define the remote path for the bash file to execute.

const rexec = require('remote-exec');
const options = {
    username: '#USERNAME#',
    password: '#PASSWORD#'
};
const bash = '/var/www/vhosts/mydomain.net/bin/task.sh';
const command = `sh ${bash}.sh`;
console.log(`executing: ${command}`);
rexec('#SERVER_IP#', command, options, (err) => {
  if(err) {
    console.log(`error: ${err}\n`);
  } 
});

Bulk queries with promises

Implementing a Promise function we can recurvise execute a list of queries to a data base. This function wait for the response of each query for execute the next of the list. [ read ]