简体   繁体   中英

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?

Run them in the background:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM