I'm a newbie on bash scripts and would like to ask what's best/easiest way to achieve the following:
- run a command in parallel (e.g. run a nodejs web app); the output of the command should be written to console as usual
- wait until a specific string occurs in output (e.g. "DB initialized")
- then run another command (e.g. command to create some DB data)
- afterwards wait until the command from 1. ends
This is my current script that does the waiting by sleep but of course this is just a workaround:
# parallel command
npm run start &
# wait for specific output
sleep 15s
# do something
node_modules/.bin/knex seed:run
# wait for parallel command to exit
wait
I found a similar questions but the output of command executed in parallel is not printed to console I think.
Background: The script is the entry point of a docker image based on the alpine variant of nodejs image.