1

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?

  • 1
    Try inserting a brief pause (like sleep 2) between actions. – user535733 May 28 '23 at 12:43
  • 1
    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 – Raffa May 28 '23 at 12:52
  • 1
    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 – Rinzwind May 28 '23 at 13:56
  • @Rinzwind, can not use for loop, there are a few parameters in the Commands those are not the same. – Devil's Dream May 29 '23 at 04:31
  • 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. – terdon May 29 '23 at 14:56

0 Answers0