Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sh screen - Wait for screen to terminate

I'm writing on a little script that does send a command to a running screen session. This command stops the screen but not instantly. I need to wait for it to finish in order to continue with the rest of the script.

This is how I stop the screen:

screen -S $SCREEN_NAME -p 0 -X stuff "`printf "stop\r"`"

How could I do this?

like image 491
BrainStone Avatar asked Aug 06 '13 18:08

BrainStone


People also ask

How do I exit screen without terminating it?

If you exit screen, by typing exit, you lose that session. To detach it, type Ctrl-a Ctrl-d (most commands in screen start with Ctrl-a, this overrides the Ctrl-a command normally used when you want to jump to the start of a line). To reconnect to it, type 'screen -r'.

How do I get out of a screen session?

Leaving Screen Terminal Session There are 2 (two) ways to leaving the screen. First, we are using “Ctrl-A” and “d” to detach the screen. Second, we can use the exit command to terminating the screen. You also can use “Ctrl-A” and “K” to kill the screen.

How do I stop a process in Linux screen?

CTRL+a and then 'k' will kill a screen session. Show activity on this post. There are a couple of 'screen' ways to kill a specific screen session from the command line (non-interactively).

How does wait work in Linux?

wait command will suspend execution of the calling thread until one of its children terminate. It will return the exit status of that command. The sleep command is used to delay the execution of the next command for a given number of seconds, hours, minutes, days. kill is used to terminate a background running process.


1 Answers

I found an solution:

You just simply check if the screen is still running and wait (sleep) for one second.

Like this:

while screen -list | grep -q $SCREEN_NAME
do
    sleep 1
done
like image 173
BrainStone Avatar answered Sep 23 '22 15:09

BrainStone