Skip to content

Instantly share code, notes, and snippets.

@koo6357
Created September 24, 2019 09:54
Show Gist options
  • Save koo6357/e2a59048840c669f7e57381b861f08ab to your computer and use it in GitHub Desktop.
Save koo6357/e2a59048840c669f7e57381b861f08ab to your computer and use it in GitHub Desktop.
run command remotely with async

run command remotely with async

function promiseExec(cmd) {
    return new Promise((resolve, reject) => {
      exec(cmd, (error, stdout, stderr) => {
        if (error) {
          reject(error);
        }
        resolve(stdout ? stdout : stderr);
      });
    });
  }
  
(async () => {
  await promiseExec(`ssh -i [pem key] [name]@[ip] [command]`);  
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment