How to list running screen sessions?

2020-02-07 14:22发布

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.

9条回答
做个烂人
2楼-- · 2020-02-07 14:41

In most cases a screen -RRx $username/ will suffice :)

If you still want to list all screens then put the following script in your path and call it screen or whatever you like:

#!/bin/bash
if [[ "$1" != "-ls-all" ]]; then
    exec /usr/bin/screen "$@"
else
    shopt -s nullglob
    screens=(/var/run/screen/S-*/*)
    if (( ${#screens[@]} == 0 )); then
        echo "no screen session found in /var/run/screen"
    else
        echo "${screens[@]#*S-}"
    fi
fi

It will behave exactly like screen except for showing all screen sessions, when giving the option -ls-all as first parameter.

查看更多
Summer. ? 凉城
3楼-- · 2020-02-07 14:46
 For windows system

 Open putty 
 then login in server

If you want to see screen in Console then you have to write command

 Screen -ls

if you have to access the screen then you have to use below command

 screen -x screen id

Write PWD in command line to check at which folder you are currently

查看更多
▲ chillily
4楼-- · 2020-02-07 14:48

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.

查看更多
登录 后发表回答