1

I want to do something like this:

#!/bin/bash screen -r session -X run 'long-cleanup-and-quit' doing-something-else ... 

Which is fine, but I want 'doing-something-else' to wait for screen. screen -X doesn't block, which is understandable.

So is there a way to have screen -r session -X run 'long-cleanup-and-quit' attach, run command, but do NOT detach? Eventually the command will terminate the process/screen so the script can continue.

My workaround so far is to just loop for the process and wait.

1 Answer 1

0

I found a great solution by incorporating an answer to a non-screen question here:

https://stackoverflow.com/a/36152028/188963

and here:

https://stackoverflow.com/a/18756584/188963

So, you can do:

(base) balter@spectre:~$ cat file123 cat: file123: No such file or directory (base) balter@spectre:~$ screen -dmS test bash -c "echo 123 > file123; bash" (base) balter@spectre:~$ cat file123 123 (base) balter@spectre:~$ screen -ls There is a screen on: 13496.test (05/19/22 12:04:13) (Detached) 1 Socket in /home/balter/.screen. 

or

screen -dmS test bash -c "top; bash"

When I attach screen -r test top is running. When I q to kill top, I drop into a bash shell.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.