10

When running 'screen ls' the screen stops with the text [screen is terminating]. I would like screen to keep the session alive and reattach to it to see the output of ls.

Of course the real thing is that I don't run screen ls, but rather a screen fsck ..., so I would like to ensure that the screen is not terminating when this command is finished.

I would love to have an answer that is useful for an already existing running screen session, so some interactive keys like C-a ... or C-a : (Enter command line mode)

Jarl
  • 305
  • 1
  • 4
  • 10

2 Answers2

9

You can enter the zombie kr command after typing Ctrl-A:, to make a running screen keep the window open after the command finishes. The kr part is specifying what keys you want to use to control the window after its command has finished -- in this case, "k" to kill/close the window, or "r" to restart the command.

Jander
  • 321
  • 1
  • 5
  • +1 for clarification that you could do this on the fly without editing your `.screenrc`. – Phil Hollenback Feb 20 '11 at 08:53
  • 1
    zombie kr onerror - this is the syntax to leave zombie screen only when exit code is > 0. I wasn't able to do it. Screen stays open even if exit is 0. When I resurrect (restart) the process it exits cleanly if 0. Someone soled this? – Anton Valqk Jun 08 '15 at 13:36
  • @AntonValqk - you should open a new question; it will be a lot more visible and you'll get better answers. – Jander Jun 08 '15 at 20:30
  • Just to report. Debian version of screen 4.3.1-1 works fine. If I start screen -d -m ./exit.sh 0 && screen -d -m ./exit.sh 1 then I see only 1 screen (the second one) as expected. – Anton Valqk Jul 25 '15 at 07:56
7

Can't you just start screen first and run fsck inside your screen session?

Anyway, add this to your ~/.screenrc:

zombie kr
verbose on

and then screen will leave your zombie session open. You can then hit r to resurrect your session although in this case it will just run your command all over again which you probably don't want. Probably what you want to do is then hit ctrl-A <esc> to enter the screen scrollback mode and browse back in your previous output.

Phil Hollenback
  • 14,947
  • 4
  • 35
  • 52
  • Yes, I could. I was just in the situation, where I already had started screen in the non-optimal way... anyway doing as you suggest may result in the shell (say bash) doing an auto-logout so it will just postpone the problem. – Jarl Mar 01 '11 at 22:47