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?
For
*nix
systems, you can use thewait
command in your shell script.wait
can take aPID
as well, so you can dowait $!
to wait on the last executed command run in background. If your commands are not running in background (no&
at the end of the command), then running your script will wait until that command finishesI found an solution:
You just simply check if the screen is still running and wait (
sleep
) for one second.Like this: