I'm trying to force GNU screen to create a "virtual" terminal, without attaching to it, execute script inside and NOT terminate session once script ends.
I tried many combinations, including:
screen -dmS udplistener /share/Sys/autorun/start_udp_listeners.sh
or
screen -S udplistener -X /share/Sys/autorun/start_udp_listeners.sh
and none of them worked. I either get session without executed script, script executes, but session is terminated once it finishes or I'm getting "No screen session found" error.
What I'm basically trying to do is to run UDP listener, written in PHP and make it work in infinte loop (don't break listening). Yes -- I could run PHP script with &
at the end, forcing PHP CLI to run as daemon. The problem is, that I'm using a piece of junk called server (QNAP -- never, ever buy this junk!) which does seems to be ignoring this. As soon as I logoff SSH session, scripts stops.
So screen
seems to be the only option. But I can't understand, why it terminates session once executed command or script ends?
EDIT: I've also tried example found in the Internet:
screen -dmS name
screen -S name -p windowname -X stuff 'mc
'
No lack! After attaching to it (screen -R name
) I see that Midnight Commander HASN'T been executed. Though example author said, it will be.
screen
, you only create one window to run a single command. When the command exits, the window closes andscreen
has nothing left to do, so it exits.screen
from closing? BTW: I still don't get the idea behind! If I callscreen -dmS name
, I create a detached window, which also has nothing left to do. But it isn't automatically closed! But when I want to execute something in that detached screen, it ends once execution is done. Why? I don't see logic here. Can have window doing nothing, but can't have window doing something and then doing nothing?