Prevent GNU screen from terminating session once executed script ends
To keep screen busy after the script completes, just keep something persistent running in a window. The simplest choice for that "something" is probably an interactive shell. Here's one way to do it (assuming bash
as the choice of interactive shell):
screen -dmS session_name sh -c '/share/Sys/autorun/start_udp_listeners.sh; exec bash'
-dm
: starts screen in detached mode-S
: sets session name for screen for easier retrieval later onsh -c '...'
: instead of simply running your script, which will terminate, usesh -c
to run multiple commandsexec bash
: after the script terminates, thesh
from above will switch over to an interactive shell (bash
), which should never exit until something external terminates it. This will keepscreen
open as long as thebash
instance is alive.
I had no luck with sh -c
on my raspberry pi 2 running Debian 7.8. But bash -c
did the job:
Command:
/usr/bin/screen -dmS test-screen bash -c "/usr/bin/top; exec bash"