sh screen - Wait for screen to terminate

2019-02-19 08:01发布

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?

2条回答
霸刀☆藐视天下
2楼-- · 2019-02-19 08:08

For *nix systems, you can use the wait command in your shell script. wait can take a PID as well, so you can do wait $! 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 finishes

查看更多
Evening l夕情丶
3楼-- · 2019-02-19 08:17

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
查看更多
登录 后发表回答