0

I am running ubuntu 16.04 server.

I'm basically making a script to do the following when the system boots:

  1. Open a new screen in detached mode
  2. Run a command in this screen
  3. Open a new "window / virtual console" in the same screen (ctrl - a - n)
  4. 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.

jbwar22
  • 113
  • Put commands like in the dupe in a file and run screen with screen -c /path/to/file. – muru Apr 05 '18 at 01:42
  • @muru how would I cd into a folder and then run my script using this method? when I put screen -t Name 0 cd /path/to/scriptin a file and run screen -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:50
  • Eithe chdir before screen -c, or do screen -t Name 0 bash -c "cd /path/to/script; ./some-command; some-other command, I'd think. – muru Apr 05 '18 at 01:56
  • @muru that didn't quite work, but I found a work-around. The command I use to start is screen -dm -c script1. then, in script1, i have screen -t name 0 bash --rcfile script2. and in script2, i have cd /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

0 Answers0