The screen -S test -X screen command
command is what you need to add windows to your daemon session, but not for the reasons you give. It works because -X takes a screen command and not a shell command, and the screen command to create a window is called, confusingly, screen. There is no exec screen command. There is no chaining either, unless you build your command using shell scripting (like this: screen -S script -X screen sh -c 'command1; command2;'
).
Calling screen -S test -X screen
with no command is useless because the default command is a shell, and once you have spawned a shell, you don't have a noninteractive (and non-devious) way to run commands inside that shell. It is better to run the command by itself, without an interactive shell. A side effect is that when the command exits, the screen window doesn't have a child any more, and will close.
Now, you can ask screen to hold the window open anyway, after the command has quit. Use the zombie
screen command to enable that. Your sequence looks like:
screen -d -m -S script
screen -S script -X zombie qr
screen -S script -X screen tail -f /var/log/messages
screen -S script -X screen tail -f /var/log/xinetd.log
To reattach interactively:
screen -S script -r
And finally, you can rewrite these -X commands as a screenrc script instead.
Screenrc:
zombie qr
screen tail -f /var/log/messages
screen tail -f /var/log/xinetd.log
Script:
screen -d -m -S script -c screenrc
Aw come on, don't use screen for this.
Use something that's actually designed to look after processes, and restart/respawn them when they die.
Anything else is just wheel-reinvention, and will never be as good or as tested.
Best Answer
look for the script's pid using
ps
check
/proc/$PID/fd/
; there should be a broken link to the script file, butcat
should work (while the script is running!):good luck!