How to perform a series of commands?
See original GitHub issueI’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:
- Created 8 years ago
- Comments:9 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep. Or write the entire thing as a bash script if you are familiar with that
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); } }); };`