2

Is there a way to take a "screenshot" of linux screen command. In other words can "screen -r" command to be called with the same behaviour as "top -b -n 1" - print contents once and exit.

Background - I have a screen process that's running on my server. I want to be able to show it's contents in web for example. Or take a snapshot and pass it to a script once in a while.

Maybe if there is a way to capture current console screen it'll work in screen.

migrated from serverfault.com Mar 27 '15 at 22:01

This question came from our site for system and network administrators.

3

You can get a 'hardcopy' of a screen session with the screen command 'hardcopy' An automated way to do this would be something like:

rm ~/hardcopy.0
screen -X -p0 hardcopy
tail -30 ~/hardcopy.0

It was also pointed out 'screen -X -p0 hardcopy -h /tmp/out.txt' might be more useful. That version will copy the entire scrollback buffer into /tmp/out.txt instead of some ~/hardcopy.<number>

  • I guess that hardcopy will contain all the data that has ever been in screen. That could be a lot. Also the screen contains positioning data. It's not just log. Like pv (ivarch.com/programs/pv.shtml). – NickSoft Mar 27 '15 at 16:51
  • Or do I get he "hardcopy" command wrong. I tried your command line but it didn't create hardcopy.0 file. What am I doing wrong – NickSoft Mar 27 '15 at 16:59
  • 1
    Try using the hardcopy command natively, i.e. Ctl-A : hardcopy That should pop up a message on your status bar, like "Screen image written to hardcopy.0" Then exactly what you see in your active window screen session should be in ~/hardcopy.0 – Corvar Mar 27 '15 at 17:07
  • I'm sorry. Hardcopy is exactly what I need. I didn't understand how it works. It's creating the "screenshot" in directory where screen was started. Could you add "-h" option to be helpful to others: screen -X hardcopy -h /path/to/hardcopy.txt -p <pid> – NickSoft Mar 27 '15 at 17:08
  • It saves it in the initial directory that screen was started. There is a "hardcopydir" command that sets the directory for future screenshots. – NickSoft Mar 27 '15 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.