Setting up "GNU Screen" to start on each login:
See:
http://github.com/write2david/screendoor
Option 1 (from the GitHub link above): Start a new screen session for each login (each session can contain multiple windows).
When you type "exit" to close the the X-windows shell window, ssh login, or tty, you will close Screen -- and the below files setup that when Screen closes, then the X-windows shell /ssh/tty closes too. Alternatively, you can just close the X-windows shell window or ssh login and whatever you were doing will continue in the background and wait for you to connect to it later (useful tip: add && exit to the end of the command before you close the window, and it will finish the command and close the session, all in the background after you disconnect).
Use the files on the Git repository (above).
They are fairly well-commented.
Option 2: Start a new screen window for each login, each using the same screen session.
When you type exit to close the X-windows shell window, ssh login, or tty, then you will not close Screen, but only the Screen window. Then you must detach from from the session to close out the X-windows shell window/ssh/tty.
Use these: .bash_login and .bashrc
They are fairly well-commented. Some inspiration comes from: http://aperiodic.net/phil/configs/bin/attach-screen
The main command in these files is:
screen -S main -X screen -t `echo $PPID`\ "`date +\(%m/%d\ @\ %I:%M%p\)`" && screen -S main -X prev && screen -S main -x -p `echo $PPID`
# Second part, the problem thus far is that the command will MOVE TO the new window on all
# First part: communicate to the "main" session ("-S main") and send the command to create a window ("-X screen") named with a combination of the date and the $PPID of the bash shell ("-t ...") -- the bash shell that started as a result of logging in
displays using that session (Alt-F1, Alt-F2, etc, all x-terms, etc.) instead of just creating the
# Third part: actually attach to this window ("-x -p ...") of the main session ("-S main")
new window in the background for us to connect to. To correct this, do:
[create new window] "&& screen -S main -X prev && " [attach to new window]
...this middle section returns ALL other logins (that this session) to their former window
Note for both options:
You can keep the line in the files that says: "screen -ln bash --noprofile"
or you can remove the "-" (minus sign) on the "shell" line in /etc/screenrc
Using Screen with Option #2
To move to another Screen session, use:
screen -ls (to display available screen sessions)
screen -x PID (to connect to a screen session)
Using the "-x" argument does not force the other bash prompt to detach.
But, if you are doing "screen -x PID" from a screen, then your first/original screen is what will receive your commands like "detach" or "show window list." So, if you detach, you aren't detaching from the destination screen (the one you got to with "screen -x") but from your original screen. And then if you detach, you're left with an attached session (the "screen -x") which you are detached from.
- So, to detach from the destination screen, use "kill" (Ctrl-A, K). This will leave the destination screen logged in, but you will be detached/logged out from it.
- Or, even better, do: "Ctrl-A a d" (see: http://lists.gnu.org/archive/html/screen-users/2005-01/msg00003.html)
- Or, you can use "exit" to leave the destination screen (that you got to with "screen -x") and you will be just back to your original screen. Of course, this will also run "exit" on the destination bash prompt.