I Don't Know How I Lived Without Screen
From UCLUG
This is not my talk yet, just fleshing it out. Work in progress. Move along, move along... chruck 15:26, 4 September 2009 (UTC)
discuss Contents, "Here's what I use"
Contents
Concepts
What Screen Is
- Face it: Linux: must use commandline
- "Window Manager"
- Allows reconnecting to sessions
- Not invasive: Gets out of the way
- Multiple windows on the same virtual terminal
- Multiple access to the same virtual terminal
Nominclature
- terminal
- display that shows standard output from computer, usually text <ALT>-F1
- virtual terminal (vt)
- terminal that may/not be attached to display <ALT>-Fx
- X terminal (xterm)
- X window program that displays vt, eg xterm, Kterm, Gnome-terminal, rxvt, Eterm
- attach
- session in current terminal
- detach
- session running in background on vt
- window
- process (usually shell) running on its own vt
- session
- an instance of screen
Use Cases
discuss later?
Commandline Options
- -ls -list
- list screen sockets
- -d [label]
- detach
- -r [label]
- reattach
- -DR [label]
- detach/reattach force (create if not existing)
- -x
- multipass [label]
- -wipe
- clean up socket list
- -S [label]
- label screen session
Concretes
Key Bindings for Commands
screen
- <CTRL>-A → screen's command prefix. All the following need <CTRL>-A prepended:
- ?
- help
- d
- detach
- c
- create a window echo zeroth, echo first, second, third
- <SPACE>, n
- next window, wraps around
- p
- prev window, wraps around
- <CTRL>-A
- last window
- 0 to 9
- jump to that window number first → third
- a
- send <CTRL>-A to vt vim
- A
- window title
- w
- show windows
- "
- goto window from list
- S
- split
- <TAB>
- focus
- <ESC>
- begin copy mode (view scrollback)
- ]
- paste
Copy Mode
- vi-like movement, searching
- <SPACE> marks what to copy
- <ESC> exits
.screenrc
# Have 1000 lines buffered to go back to via C-a esc (-h) defscrollback 10000 # On the OLPC, the 'erase' key becomes 'NUL'. This fixes: bindkey -d "\000" stuff "\010" caption always screen su - screen mutt screen less +F /var/log/messages screen
Conclusions
Gotchas
- $DISPLAY
- $TERM
- screen within screen
- other programs that use <CTRL>-A (minicom, vim)
- <BEL> → vbell
- multi-display on different-sized vt
Resources
- <CTRL>-A ?
- man screen
- info screen
- uclug
- Eric
Newbie Questions
Your turn to ask
Guru Hints
Auto-reconnection script
The following script attempts to reconnect you to the last screen session that your remote IP started via SSH. If multiple exist, it reconnects you to the first available session. If none are available, it creates a new session. Just stick this in your ~/.bashrc file:
if [ -n "$SSH_CONNECTION" ] && [ -z "$SCREEN_EXIST" ] && [ -z "$BASH_EXECUTION_STRING" ]; then export SCREEN_EXIST=1 client_id=`echo $SSH_CLIENT | awk '{ print $1 }'` count=`screen -ls | grep "$client_id" | grep '(Detached)' | wc -l` # Check to see if there's an existing session from this IP if [ $count -gt 0 ]; then session_id=`screen -ls | grep "$client_id" | grep '(Detached)' | head -1 | awk -F'.' '{ print $1 }'` screen -DR $session_id else screen -R $client_id fi # Uncomment this line if you want your SSH session to disconnect when you exit the screen session # However, if this script has bugs...you may just lock yourself out of your machine, short of a live CD... #exit fi