9

I need to start multiple apps running in shells and monitor their execution. Currently I have a main script that launches every apps in a new gnome-console but I would prefer to launch them all in the same window in split screens.

This post Multiple shells in one window explains how to use split screens with many type of console applications such as screen, terminator and byobu. This works fine manually but I would like to be able to start all my apps in a split screen console automatically from my main scrip. In the documentation from the tools mentioned above there was nothing I could fine to achieve this automatically from a script.

Any ideas?

2 Answers 2

7

You can make a custom screen config file that will open up multiple splits and launch your scripts in them. It would look something like this:

screen script1.sh # Open first screen and launch first script
split             # Make second split
focus             # Switch to second split
screen script2.sh # Open second screen and launch second script
split             # Make third split
focus             # Switch to third split
screen script3.sh # Open third screen and launch third script

Put this in a file called myscripts and launch screen with screen -c myscripts. If you prefer vertical splits, just add -v to the split commands.

If you'd like a grid layout, try something like this:

screen script1.sh # Open first screen and launch first script
split -v          # Make second split
focus             # Switch to second split
screen script2.sh # Open second screen and launch second script
split             # Make third split
focus             # Switch to third split
screen script3.sh # Open third screen and launch third script
focus             # Cycle back to first split
split             # Split first split horizontally
focus             # Switch to new split
screen script4.sh # Open fourth screen and launch fourth script
4
  • Thanks a lot this worked like a charm. The only other issue is that after starting my multiple scripts, I can C-a C-d to return to my terminal but when I do "screen -r" it resumes to my last open tab and I cannot see the output of the other tabs anymore. "screen -ls" shows only one instance but I can see that all my scripts are still running in the process list with "ps". So how can I detach my multi-tab screen and go back to it with the same state?
    – jmbouffard
    Jun 21, 2011 at 15:22
  • I found a superuser question about that: superuser.com/questions/69816/… Looks like a thorny problem. It occurs to me that you might also be able to make a macro that reestablishes your splits. Jun 21, 2011 at 20:01
  • The tip from the superuser forum doesn't seems to work for me because the nested session doesn't seem to use my configuration when I launch it with the -c option.
    – jmbouffard
    Jun 23, 2011 at 18:52
  • I also tried your other idea to reestablish my splits with a config file such as the one shown in your answer. But I guess I need to use "screen -r -c macro" but it seems I cannot combine the -r option with -c because it doesn't take my commands into account. "-c" alone re-establishes my splits with empty screens, "-r -c macro" does the exact same thing as "-r" alone and does not create any split.
    – jmbouffard
    Jun 23, 2011 at 18:57
0

I know it's an old question, but it is worth mentioning this tool that does just what you need in an excellent way:

https://github.com/pvolok/mprocs

It runs in one terminal all the needed processes and allow to control them (kill, stop, start, restart). Ideal for running local servers (flask, expressJS, etc)

Example:

mprocs "sleep 5" "sleep 2" vi

mprocs running 3 processes

2
  • Did this tool exist 11 years ago when the question was asked?
    – David
    Sep 28, 2022 at 14:43
  • No, they publish the first version on Aug/2021 Sep 29, 2022 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .