send command to an already running screen session
Actually it's quite simple. You can use the following:
screen -S sessionname -X stuff 'command'`echo -ne '\015'`
echo -ne '\015'
emulates pressing the Enter key.
NOTE: that 'stuff' is a screen command. http://www.gnu.org/software/screen/manual/screen.html#Stuff
Sounds like you want:
$ screen -S test -d -m -c /dev/null -- sh -c 'date; exec $SHELL' -S test: name this session -d -m: start screen detached -c /dev/null: ignore ~/.screenrc (provide a different file or drop this option, as needed) --: end of screen options sh -c 'date; exec $SHELL': command for screen to run, note that if this command was just 'date' then screen would exit immediately. if you don't want to exit screen after your command exits, then you might use: $ screen -S test -d -m -c /dev/null -- your command here
Or maybe you just want dtach.
screen -S <session_name> -X screen [-t <title>] <shell_command> [<args>]
Open a new window (with title title) in an existing session named session_name, and execute shell_command (with optional arguments args)