如果存在GNU Screen连接,如果不存在则创建

时间:2012-05-03 14:54:01

标签: gnu-screen

目前,我正在iPad上使用GNU屏幕,并在连接丢失的情况下利用屏幕作为安全措施。目前,我只是将屏幕-S ipad作为第一个命令运行,但有没有办法让它自动连接到旧的ipad会话(如果存在的话)(如果不存在则创建它)?我的一个警告是,我想在一个命令中自动执行此操作。

1 个答案:

答案 0 :(得分:24)

-D -R选项会使屏幕在必要时尝试分离或创建。

screen -D -R -S ipad

我建议您查看屏幕手册中的所有-d|D -r|-R|-RR选项,因为有很多类似的结果。

-d -r
    Reattach a session and if necessary detach it first. 
-d -R
    Reattach a session and if necessary detach or even create it first. 
-d -RR
    Reattach a session and if necessary detach or create it. Use the first session if more than
    one session is available. 
-D -r
    Reattach a session. If necessary detach and logout remotely first. 
-D -R
    Attach here and now. In detail this means: If a session is running, then reattach. If necessary
    detach and logout remotely first. If it was not running create it and notify the user. This is
    the author's favorite. 
-D -RR
    Attach here and now. Whatever that means, just do it. 
    Note: It is always a good idea to check the status of your sessions by means of "screen -list".