Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Screen connect if exists, create if not

Tags:

gnu-screen

Currently, I'm using GNU screen on my iPad and utilizing screen as a safety in the event the connection is lost. Currently, I just run screen -S ipad as the first command, but is there a way to have it automatically connect to the old ipad session if it exists (and create it if not)? My one caveat is that I'd like to do this in one command, and automatically.

like image 341
bswinnerton Avatar asked May 03 '12 14:05

bswinnerton


1 Answers

The -D -R options will make screen try to detach or create if necessary.

screen -D -R -S ipad

I recommend you taking a look at all the -d|D -r|-R|-RR options in the screen manual, since there are many with similar results.

-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". 
like image 172
KurzedMetal Avatar answered Oct 24 '22 09:10

KurzedMetal