question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to perform a series of commands?

See original GitHub issue

I’m wondering how I could use this module for running a series of conditional ssh commands. For example:

var folder = "example";
exec('cd ' + folder, 'ubuntu@my-remote.com', function (err, stdout, stderr) {
  if(stdout.indexOf("No such file or directory") {
    exec("mkdir " + folder, 'ubuntu@my-remote.com', function (err, stdout, stderr) {

    });
  }
  exec("do something", "ubuntu@my-remote.com", function (err,stdout,stderr) {

  });
})

Is this a valid approach? Is it necessary to provide the credentials for every command? Any suggestions?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mafintoshcommented, Feb 18, 2016

Yep. Or write the entire thing as a bash script if you are familiar with that

stream.write(`
  # this is a bash script
  if git status; then
    git pull
  else
    git clone some-url
  fi
`)
0reactions
httpetecommented, Jan 8, 2019

Maybe this will help you. Promisifying this needs a little customization:

`

const util = require(‘util’);

const sshAsync = util.promisify(exec); // (A) sshAsync[util.promisify.custom] = (cmd, creds, callback) => { return new Promise((resolve, reject) => { if (callback.err) { reject(callback.stderr); } else { resolve(callback.stdout); } }); };`

Read more comments on GitHub >

github_iconTop Results From Across the Web

4.3. Running Several Commands in Sequence - O'Reilly
Another rather simple solution is to type those commands into a file and then tell bash to execute the commands in the file—i.e.,...
Read more >
excel - Open one command window and execute a series of ...
Use a string variable to build your list of commands. Follow each command with vbNewLine. Then pass the whole string variable to the...
Read more >
How to run multiple commands one after another in cmd
Run multiple commands one after another in cmd ... Try using the conditional execution & or the && between each command either with...
Read more >
The Complete List of Command Prompt (CMD) Commands
A complete list of the over 280 Command Prompt commands across Windows 11, 10, 8, 7, Vista, and XP, including full descriptions of...
Read more >
List of Command Line Commands - Codecademy
Each directory contains scripts for the command line to execute. PATH lists which directories contain scripts. pwd. $ pwd /home/ccuser/workspace/blog. pwd ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found