Brandon
Brandon

Reputation: 1409

Run two ongoing commands in bash script

So, I'm new to shell scripts and I'm really doing this as a learning exercise. My problem is pretty simple. To run my Node app, I need to start mongod and start nodemon. Truth is, it doesn't matter what they do, but the important part is that they are continuous and both have output.

I've gotten as far as the code example below, but what happens is mongod runs and then stops. Of course, exiting it stops the process and then nodemon runs. How can I make them both run? I've tried using && and that didn't work.

I also realize that maybe the best option is running mongod in one shell window and nodemon in the other. Any help would be much appreciated.

#!/bin/bash
# Run App

chmod 755 run.sh;
sudo mongod;
sudo nodemon --debug app.js;

Do I need to use a conditional block to see if mongo is running and then move on? Or is it just best practice to run them in separate windows?

Upvotes: 1

Views: 632

Answers (1)

jman
jman

Reputation: 11586

Run them in the background:

sudo mongod &
sudo nodemon --debug app.js &

Upvotes: 3

Related Questions