1

I have been using screen for a while, but the process I am running seems to terminate at times, closing the screen out. So I have to reopen the screen again.

I was wondering if it was possible to have a shell script, or just a single instruction executed on screen termination, inorder to reopen the screen automatically unless if I force close it

I love how easy it is to send commands to GNU Screens and i would love to still have that functionality.

edit: In the best case scenario,my screen shouldnt terminate unexpectedly, but if it does. I want to do two things, 1) log time and 2) reopen screen with exact same parameters. but if reopening screen has the screen terminate again. I want to exit out. I would also want to be able to exit out on demand. A shell script would be bad imo, because of nesting of screen, and not enough time to force the upper screen to close, though i could add a sleep timer... anyways this is just a bodged method, I was interested in a better way to achieve this.

6
  • I was thinking if I made a shell script,put my screen command as the first instruction, and called that shell script again within that script in the second, I would achieve something close to what I need.... but I am unsure. Since I am working on a remote server..
    – Blaine
    Feb 9, 2020 at 5:29
  • 1
    One can create simple shell code that repeats the given command. It could work with or without screen, so it's a general approach. But even if a screen-specific solution exists and you would prefer this, I think you should edit and add details to the question: should the command be resurrected (1) always? (2) or only if it succeeds? (3) or only if it fails? (4) Including (or excluding) when it's interrupted on demand with Ctrl+C? // The simplest example is like while true; do your_command; done. It doesn't rely on screen but I believe you can run it inside screen. Feb 9, 2020 at 7:30
  • sorry for the delay, I edited my original post with additional details....
    – Blaine
    Feb 12, 2020 at 12:02
  • I never considered nesting screens. Your problem seems to be with a situation where the process is directly under screen: screen – process. The process dies and screen dies. My idea was like: screen – script – process. When the process dies, the script can do anything you designed it to do. It can restart the process, write to a logfile, increase count or exit, or whatever. I think the screen will notice nothing unless the script exits. And the script exits upon conditions you choose. Feb 12, 2020 at 12:14
  • 1
    Do not call the script again. Run screen with the script inside and let the script resurrect the command if needed. You can do this from another, outer script if you want to automate the whole process. There is at most one outer script in total, exactly one screen in total, exactly one inner script in total, and at most one your_command at any given time (but possibly many in total). Feb 15, 2020 at 17:39

0

You must log in to answer this question.

Browse other questions tagged .