Issue
I am having a scenario where I need to create a script file that runs a couple of commands.
- node index.js which runs continuously
- ./gradlew run which also run continuously
- some commands which will run and finish automatically
I want to write one script file that does all the jobs like running the node server, Gradle run, and also other commands. I'm thinking of one of the approaches to creating a new terminal tab and executing the commands in it. But I'm unable to find the exact code to create a new tab irrespective of the operating system.
Solution
You can use one terminal for this. Just run a command in background. You can do this by adding &
at the end of the line. The commands stdout will still log to the terminal session.
# Sorry for the Polish date
while true; do echo $(date); sleep 2; done &
[1] 8873
czw, 28 paź 2021, 09:41:52 CEST
user@user-pc:~$ czw, 28 paź 2021, 09:41:54 CEST
czw, 28 paź 2021, 09:41:56 CEST
czw, 28 paź 2021, 09:41:58 CEST
If you want to bring back the job to the foreground fg
.
user@user-pc:~$
user@user-pc:~$ fg
while true; do
echo $(date); sleep 2;
done
czw, 28 paź 2021, 09:48:07 CEST
czw, 28 paź 2021, 09:48:09 CEST
^C
So the script finally could look like this:
#!/bin/bash
./task1 &
./task2 &
./task3
Answered By - Cloudziu Answer Checked By - Cary Denson (WPSolving Admin)