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?
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'.
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With