Is it possible to look at the contents of a screen session without attaching to it?
Asked Answered
V

3

7

Is it possible to peek at the contents of a running screen session?

In order words, look through the window without going in to the room!

e.g.

ssh [email protected] screen --look (and show me what's happening)

I suppose a bit like a quick attach and detach in one go while using SSH.

Do you follow me?

Vanward answered 26/3, 2020 at 12:19 Comment(0)
S
2
screen -x

Attach to a not detached screen session. (Multi display mode). Screen refuses to attach from within it‐ self. But when cascading multiple screens, loops are not detected; take care.

You could combine it with -X hardcopy option

screen -x -X hardcopy /tmp/hardcopy.txt
Shuler answered 28/3, 2020 at 1:38 Comment(3)
Alas, this does not work the way I wanted it to. The option -x just seems to reattach to the running screen and stay reattached... which is not what I want. Yes, I know I can just 'ssh -t [email protected] screen -rd' which is what I normally do. However, what I want is like an all-in-one series of commands where it would attach, show me what's running, then detach all in one go... do you see what I mean? For example, just like the good old 'ssh user@somehost uptime' - except peek at the running screen session and show me what's happening, then detach and log out of ssh in one go! :-)Vanward
Yes I understand but this feature does not exist in screen. How I said, you can combine it with -X hardcopy. ssh user@somehost "screen -x -X hardcopy /tmp/hardcopy.txt; cat /tmp/hardcopy.txt"Niphablepsia
Wow, that works... now I see what you mean! Nice, and many thanks! :-)Vanward
N
0

I know its late , but I found a decent way to do it without restarting already running process in screen is :-

  1. Attach to your screen with screen -r

  2. Enter Ctrl+A and then Shift+; (a small command window will open)

  3. Enter :log on

  4. then detach the current screen by Ctrl+A and Ctrl+D

  5. And you can see output with tail -f -n 50 screenlog

(where -f tells tail to keep following output and -n 50 shows last 50 lines of output , screenlog is the name of file created in the directory where screen session was inititated )

(Optional - you can set the name of logfile before you turn on log with Ctrl+A & then Shift+; and entering name like logfile mylog

Nic answered 14/8 at 6:47 Comment(0)
V
0

This works for me ...

ssh user@somehost "screen -x -X hardcopy /tmp/hardcopy.txt; cat /tmp/hardcopy.txt"
Vanward answered 14/8 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.