views:

2189

answers:

6

I have a bunch of servers, on which I run experiments using screen. The procedure is the following :

  1. ssh to server XXX
  2. launch screen
  3. start experiments in a few tabs
  4. detach screen
  5. disconnect from the server

While the experiments are running, I can easily find on which servers they are by sshing to all servers and listing my running processes (using top or ps).

However, once the experiments are finished, how could I find on which servers I have a screen session opened (so that I can have a look at the output, relaunch them, etc.) ?

PS: my experiments do print their output to files, too... but this is not the point of my question.

+3  A: 

The command screen -list may be what you want.

See the man

Zoredache
Thanks, that's what I was looking for. However, as joshperry's answer is more complete, he gets accepted.
Wookai
+2  A: 

I'm not really sure of your question, but if all you really want is list currently opened screen session, try:

screen -ls
skinp
Thanks, that's what I was looking for. However, as joshperry's answer is more complete, he gets accepted.
Wookai
No problem... He deserved it :P. Glad you found what you wanted.
skinp
+3  A: 

To list all of the screen sessions for a user, run the following command as that user:

screen -ls

To see all screen sessions on a specific machine you can do:

ls -laR /var/run/screen/

I get this on my machine:

gentle ~ # ls -laR /var/run/screen/

/var/run/screen/:
total 1
drwxrwxr-x  4 root utmp   96 Mar  1  2005 .
drwxr-xr-x 10 root root  840 Feb  1 03:10 ..
drwx------  2 josh users  88 Jan 13 11:33 S-josh
drwx------  2 root root   48 Feb 11 10:50 S-root

/var/run/screen/S-josh:
total 0
drwx------ 2 josh users 88 Jan 13 11:33 .
drwxrwxr-x 4 root utmp  96 Mar  1  2005 ..
prwx------ 1 josh users  0 Feb 11 10:41 12931.pts-0.gentle

/var/run/screen/S-root:
total 0
drwx------ 2 root root 48 Feb 11 10:50 .
drwxrwxr-x 4 root utmp 96 Mar  1  2005 ..

The files are Unix Sockets.

joshperry
Thank you for your complete answer, that's exactly what I was looking for !
Wookai
A: 

So you're using screen to keep the experiments running in the background, or what? If so, why not just start it in the background?

./experiment &

And if you're asking how to get notification the job i done, how about stringing the experiment together with a mail command?

./experiment && echo "the deed is done" | mail youruser@yourlocalworkstation -s "job on server $HOSTNAME is done"
JosefAssad
I'm using screen so that I can disconnect from the servers without terminating my experiments. The question was not how to get notifications (though the mail could be a nice way of doing it), but how to find if a given machine had an opened screen session. Thanks anyway for your answer !
Wookai
+1  A: 

multiple folks have already pointed that

$ screen -ls

would list the screen sessions.

Here is another trick that may be useful to you.

If you add the following command as a last line in your .bashrc file on server xxx, then it will automatically reconnect to your screen session on login.

screen -d -r

Hope you find it useful.

samurai
+1  A: 

While joshperry's answer is correct, I find very annoying that it does not tell you the screen name (the one you set with -t option), that is actually what you use to identify a session. (not his fault, of course, that's a screen's flaw)

That's why I instead use a script such as this: ps auxw|grep -i screen|grep -v grep

Lo'oris