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

13 March 2012

107. Fun with gnu screen -- setting up a screenrc

This is going to be a short post.

The problem:
If I have three nodes on a cluster, each with htop installed, how do I set up gnu screen so that it automatically signs in to each node and starts a copy of htop on each node, and display the output in a split window? Basically, how to you open screen instances and inject commands in them?

...like so. Guess which computer is running a full gnome-shell environment...


The solution:
create a file called multitop.screenrc:

screen ssh 192.168.1.101
stuff htop\015
title node01
split
focus
screen ssh 192.168.1.102
title node02
stuff htop\015
split
focus
screen ssh 192.168.1.103
title node03
stuff htop\015
stuff string injects string into the active window. \015 basically injects <enter>.

start screen using
screen -c multitop.screenrc 
and as usual,don't exit using exit or q, but use C+a - d to leave it running.


To make things a bit prettier and to enable users to reconnect to a running session, edit /etc/screenrc:

multiuser on
acladd me
defscrollback 5432
termcapinfo xterm|xterms|xs|rxvt ti@:te@
caption     always        "%{+b rk}%H%{gk} |%c %{yk}%d.%m.%Y | %72=Load: %l %{wk}"
hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%"
and
sudo chmod +s /usr/bin/screen
sudo chmod 755 /var/run/screen


If you start a session using e.g.
screen -S mytest
as user me

then other users can connect using
screen -x me/mytest

23 February 2012

73. Gnu screen- attach to a running screen session

Follows this with minor amendments.

The issue:
You start e.g. a compile or a number-crunching job on your work computer, and go home while leaving it running. When you get home you log on to your work computer via ssh, and want to connect to the terminal in which the job is running i.e. connect to the tty.

Another use for screen is if you are working over an unstable connection -- if you get booted off the screen session continues to run, so whatever was running in it is still sound. A normal pts will die and crash.

A solution using screen:
Be aware that this can cause a potential security risk.

1. install gnu screen
sudo apt-get install screen

2. enable multi-user mode
sudo chmod +s /usr/bin/screen
sudo chmod 755 /var/run/screen

Edit /etc/screenrc and add the following lines anywhere

multiuser on
acladd me
If you want primitive scrolling (shift + page up/down)
termcapinfo xterm|xterms|xs|rxvt ti@:te@
Replace me with the local username.

3. On your work computer,
screen -S testing

4. Start whatever job you were thinking of and leave it running

5. From home ssh into your work computer then
screen -x me/testing

Another neat thing is that both terminals look the same no matter whether you are at your work computer or at your home computer. Ergo, it may be a useful way of helping people remotely with their computers too.

6. To disconnect gracefully
Hold CTRL+a+d

Do not type exit or anything like that, as it will close the screen instance completely.

For a gnu screen cheat sheet, look here:
http://www.totiso.com/2009/05/03/gnu-screen-cheat-sheet