Wednesday, August 20, 2008

Script and Screen


At work we use script and screen for co-development and training.

If you want to work with others in a command line environment and don't use these yet, then you should definitely read this post.

Here's how we use it:

The first thing we do when we work together is we all ssh into the box we will work on.

Then we have the person driving start screen, a terminal multiplexor, and then script, a command logging tool.

Then everyone else logs into the drivers multiuser terminal session run by screen by typing screen -x, and can take over driving when needed. We all can read and write to the same set of terminals, and detach or reattach to the session as we come and go.

When we're done, we copy the drivers /home/driver/typescript file to someplace where we keep old training files like /backup/it/training/how_to_debug_that_thing.txt.

NOTE: screen can be used without script to do a similar job, and script can be used without screen to do a similar job. We just happen to use both.

Script:

Just type script to start it. It will start logging to your home directory in a file called typescript.

If you don't want to use screen, and just want to watch what someone else is doing, you can also try the -f option to flush output after each write. This is nice for telecooperation: One person does ‘mkfifo foo; script -f foo’ and another can supervise real-time
what is being done using ‘cat foo’.

Screen:

Setting up and using GNU screen as a collaborative development environment (pay careful attention to the slashes).

Your user is peter, and you want to pair program with user mike.
1) Install GNU screen on the server and learn the ScreenBasics.
2) Drop the following two lines into /home/peter/.screenrc:
multiuser on
addacl mike
3) Execute the following two commands to allow mike to use your screen sessions:
chmod +s /usr/bin/screen
chmod 755 /var/run/screen
4) Peter is already logged into a screen session
5) Mike can type:
screen -x peter/
6) Peter and mike can now look a the same screen windows/terminals and share the same i/o

ScreenBasics - commands you will actually use, in the order you will probably use them














'screen'start screen session
'Ctrl-a c'create a new terminal
'Ctrl-a "'list the terminals in this session
(then hit the number of the terminal you want to switch to and hit enter)
'Ctrl-a Shift-a'rename a terminal
'Ctrl-a F'flush the screen when it gets screwed up
'Ctrl-a k'kill a terminal
'Ctrl-a d'detach from session
'screen -r're-attach to a screen session
'Ctrl-a S'make two terminal panes in the window
'Ctrl-a Shift \split the screen vertically
'Ctrl-a Tab'next pane in this window
'Ctrl-a Q'go back to one pane, current window



Other Screen Notes:

1) If you don't want to use script, you can get screen to record sessions as well. I think it's 'Ctrl-a H'.

2) The default screen key bindings collide with readline and emacs commands. I should look into remapping them someday.  Hit Ctrl-a-a to go to the beginning of a line.

3) Record and play back real-time textcasts with scriptreplay as follows:

script -t 2>timingfile testscriptfile
scriptreplay timingfile testscriptfile

Note: scriptreplay is a tiny perl script that was left out of most red-hat derived linux-util packages to date. You can get it from a debian derived distro or find it here.

4) If you are using MacOS, you are behind on every open source software application in existence.   You will have to compile and patch screen, script, emacs, and whatever else you use to get a modern functionality set.

5) You can access the scrollback buffer by hitting Ctrl-[.  After that point, the normal vi-like scrolling commands work i-j-k-l, Ctrl-u-b-d-f.  Hit esc to get out of the mode that allows you to scroll.

Links:

** The homepages for script and screen (for GNU/Linux users):

Script is in util-linux: ftp://ftp.kernel.org/pub/linux/utils/util-linux/

Screen: http://www.gnu.org/software/screen/

** Some of the better articles on screen:

http://www.sun.com/bigadmin/features/articles/gnu_screen.html

http://www.kuro5hin.org/story/2004/3/9/16838/14935

http://aperiodic.net/screen/terminal

http://aperiodic.net/screen/multiuser

http://www.linuxjournal.com/article/6340

http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml

Patching Screen for MacOS: http://old.evanmeagher.net/2010/12/patching-screen-with-vertical-split-in-os

1 comment:

rsb said...

Found out how to record co-development sessions with timing for subsequent playback with script. It will even handle most of your editing sessions almost perfectly!:

script -t 2>timingfile testscriptfile

scriptreplay timingfile testscriptfile