I am running ubuntu 16.04 server.
I'm basically making a script to do the following when the system boots:
- Open a new screen in detached mode
- Run a command in this screen
- Open a new "window / virtual console" in the same screen (ctrl - a - n)
- Run another command in this "window"
When I connect to the screen after logging into this machine, i need to be able to ctrl-c a command running within the screen without the screen destroying itself.
Here is what I've tried so far:
screen -md -S name command
This works ok, except if the command finishes the screen destroys itself
screen -md -S name bash -c "command"
this just doesn't work and I don't know why
screen -md -S name bash --rcfile <(echo 'command')
Not quite sure (again) why this doesn't work.
screen -md -S name bash --rcfile scriptThatRunsCommand
This does exactly what I want for the first part, but I still do not know how to run another process in a new window of the screen
Basically all I need is to be able to run something else in a new "window" of this screen
I'd assume that there is a command built into screen that can do this, but I have not been able to find any documentation or online advice. I would also assume that whatever screen command would be used for this would have to also run bash --rcfile
so I would be able to ctrl-c back to the prompt in the screen "window."
Whatever command does this can run from within the screen on the first "window" before my command runs or can run from outside the screen. Either is acceptable.
screen
withscreen -c /path/to/file
. – muru Apr 05 '18 at 01:42screen -t Name 0 cd /path/to/script
in a file and runscreen -c /path/to/file
I get "cannot exec 'cd': no such file or directory. could I even run multiple commands with this method such as cd and then my script? – jbwar22 Apr 05 '18 at 01:50chdir
beforescreen -c
, or doscreen -t Name 0 bash -c "cd /path/to/script; ./some-command; some-other command
, I'd think. – muru Apr 05 '18 at 01:56screen -dm -c script1
. then, in script1, i havescreen -t name 0 bash --rcfile script2
. and in script2, i havecd /path/to/app; ./start
. I don't think this is exactly a duplicate as long as I edit my question to ask how to "create a detached screen running two windows with processes in separate directories that don't quit when I ctrl-c" – jbwar22 Apr 05 '18 at 02:12