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

No comments: