Score:1

Run multiple command in multiple background screen

us flag

I have a long-running process command and I am splitting it into 10. This is why I am trying to run 10 commands instead of 1 using screen. If I open the screen manually and run those commands one after another then it is going fine. But I want to automate the task. This is why I wrote the following shell script. Unfortunately sometimes a few of the screens not loaded automatically.

screen -dmS Screen01
screen -S Screen01 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen02
screen -S Screen02 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen03
screen -S Screen03 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen04
screen -S Screen04 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen05
screen -S Screen05 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen06
screen -S Screen06 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen07
screen -S Screen07 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen08
screen -S Screen08 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen09
screen -S Screen09 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

screen -dmS Screen10
screen -S Screen10 -p 0 -X stuff 'Some command that run for more than 20 hours\n'

Sometimes it there is Screen07 missing sometimes Screen04 missing and sometimes multiples are missing.

How can I automate this process?

user535733 avatar
cn flag
Try inserting a brief pause (like `sleep 2`) between actions.
Raffa avatar
jp flag
You most likely don't need screen to keep your process running after you disconnect. You can use `bash`'s job control instead ... See for example https://askubuntu.com/a/1460233 and https://askubuntu.com/a/1461645
cn flag
you do not need the "screen -dmS ScreenNN" Plus put it all in a for-loop with a sleep at the end of the loop
Devil's Dream avatar
us flag
@Rinzwind, can not use for loop, there are a few parameters in the Commands those are not the same.
terdon avatar
cn flag
Please [edit] your question and add those details then. I really don't understand why you would want to complicate things by using `screen`. If you explain exactly what functionality you need, we will be able to help more.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.