1

I have little experience with screen, and recently found out that it has windows. Before this, I was just creating a new session for every process I needed to run (I know, right?). However, now that I found out, I want my processes to run in a single screen instead. On startup, several processes need to be ran in windows in this screen, but I can't figure out how to run them in a specific window, creating a session if it doesn't exist. I'd like the processes to take up specific windows (8 and 9).

I know that screen -dmS main bash will execute bash in a screen session named main, however this will always create a new session. I don't know what to run so that bash is running in window 9 in a session called main, whether or not that session existed beforehand, with only one session main existing after.

What command(s) do I need to run at startup to make this happen?

0

You need to use -ls flag.

bash-4.3$ screen -dmS main bash
bash-4.3$ screen -ls
There is a screen on:
    7144.main   (2017年01月28日 20时05分05秒) (Detached)
1 Socket in /var/run/screen/S-xieerqi.

-ls will show you existing sessions, and you can reattach to them with -x flag. Script-wise, you could do something like this:

bash-4.3$ my_session=$(screen -ls | awk '/[[:digit:]]\.main/{print $1}')
bash-4.3$ screen -x $my_session

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.