I would like to launch some application inside screen session but from a script.
Without script I would just launch screen, then open N windows with crtl-a-c and execute programs in each windows.
I tried the following
screen -d -m -S test
screen -S test -X exec tail -f /var/log/messages
screen -S test -X screen
screen -S test -X exec tail -f /var/log/xinetd.log
But when I attach the session tail is not running. If I attach the session just after screen -d -m -S startup
and run screen -S startup -X exec tail -f /var/log/messages
from another terminal it works.
Did I miss something ?
Edit after AlexD answer:
An half working solution is
screen -d -m -S test tail -f /var/log/messages
screen -S test -X screen tail -f /var/log/xinetd.log
Chaining screen command (the one after -X) with the command is working while exec is not probably because exec expect a current window to be defined while there is no current one when screen is detached. Thanks to AlexD for this tips.
But there is a weird side effect : when the program stop (if you attach the screen session and crtl-c the tail, or kill tail) the screen window will close.
So the behavior is not the same as Crtl-A c and run the command
Another side effect is that you can't chain 2 commands
screen
always terminates when the command with which is was launched ends - it's a normal feature of the tool :) ..so if you runscreen top
, when you quittop
,screen
will quit, too