Showing posts with label screen. Show all posts
Showing posts with label screen. Show all posts

Sunday, April 15, 2012

GNU Screen: Useful tips

Here are the useful trick for GNU screen:

1. Give access to other users on the screen:


  - Let say screen "test" is running on host 15.25.125.148 with user "xyz"
  - run command "Ctrl a :"
  - type "multiuser on" to enable multiuser mode
  - type "acladd <unix username>" (to whom you want to give access)
  - type "aclchg <args>" to change permissions on the screen for that user
  - Now the user will login on that host via command "ssh user@15.25.125.148"
  - attach to screen with command "screen -x xyz/test"

2. Changing session name of the running screen

The default session name created by the screen command is constructed from the tty and host names, which isn't very intuitive. To change this session name, run this command on your screen session

Ctrl a :sessionname newSessionName
3. Send a command to a window in a running screen session from the commandline 


screen -x <screen session name> -p <window number or name> -X stuff '<command>\012'
4. Create screen session with commands running

- First, create  .screenrc_test with following contents where you specify your tabbed sessions and commands

startup_message off
vbell off
caption always "%{= bb}%{+b w}%n %h %=%t %c"
hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"
activity "Activity in %t(%n)"
deflogin on
shell -/bin/bash

screen -t TAB1
stuff "cd $HOME && ls -1rt | tail -1 | xargs tail -f  \012"
screen -t TAB2
stuff "cd $HOME && top  \012"



- Run screen -S test -c .screenrc_test

5. Starting screen and detach automatically

screen -S test -dm -c .screenrc_test

Tuesday, October 30, 2007

GNU Screen utility

Screen, this command might not be well known to many people but its one of those programs that you just can’t stop using once you’ve started. Previously I used VNC to connect the remote servers, but now i have stopped using it and use SCREEN on a regular daily basis and it’s really easy to use.
Screen program provides the following functionality:
  • Remote terminal session management (detaching or sharing terminal sessions)
  • Unlimited windows (unlike the hardcoded number of Linux virtual consoles)
  • Scrollback buffer (not limited to video memory like Linux virtual consoles)
  • Copy/paste between windows
  • Split terminal (horizontally) into multiple regions
  • Locking other users out of terminal
  • Screen is an easy way to allow processes to continue running after the session is terminated, if you lose connection screen will save your spot
Following is the content of my ~/.screenrc file
************************************************************
startup_message off
vbell off
caption always “%{= bb}%{+b w}%n %h %=%t %c”
hardstatus alwayslastline “%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<” activity “Activity in %t(%n)” shell -/bin/bash
************************************************************
Screen Commands
(screen) Start screen
(screen -S vishnu) Create a screen session with the name vishnu
(screen -r vishnu) reconnect to the session with the name vishnu
(screen -x ) Connect to an existing screen session
(screen -d ) detaching a screen session
(screen -r) reattaching the screen session
(Ctrl+a c ) New window
(Ctrl+a n ) Next Window
(Ctrl+a p ) Previous Window
(Ctrl+a ” ) Select window from list
(Ctrl+a Ctrl+a) Previous window viewed
(Ctrl+a <0-9> ) Select the numbered window
(Ctrl+a A ) Set window title
(Ctrl+a K ) Kill window
(Ctrl+a d ) Detach screen from terminal
(Ctrl+a x ) Lock Session
(Ctrl+a : ) Goto screen command prompt
(Ctrl+a ? ) Show key binding/command names
(Ctrl+s ) Pause the output on screen
(Ctrl+q ) Resume the output on screen
(Ctrl+a :escape ^Ww) Change key binding to w character
(Ctrl-a * ) List all currently attached displays. (displays)
(Ctrl-a Ctrl\) Kill all windows and terminate screen. (quit)
(Ctrl-a w ) List all windows. (windows)
(Ctrl-a h ) Write contents of the current window to the file hardcopy.n. (hardcopy)
(Ctrl-a H ) Begin/end logging of the current window to the file screenlog.n. (log)
(Ctrl-a ' ) Prompt for window name or number to switch to. (select)