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`); } });