Results 1 to 4 of 4

Thread: How to launch commands in a separate Screen session via a bash script at startup?

  1. #1
    Join Date
    Apr 2012
    Location
    Somewhere in Nevada...
    Beans
    141
    Distro
    Ubuntu 12.04 Precise Pangolin

    How to launch commands in a separate Screen session via a bash script at startup?

    To start the server applications I'm running takes several steps, so I've decided to put it in a bash script to make it easier. When I do start it, I begin by opening a new screen session. The issue is, in my script, I've noticed that none of the other commands execute until the new Screen session is closed. Any Ideas?
    The main difference between Windows forums and the Ubuntu forums is that the Ubuntu forums has hundreds of questions and thousands of answers, but Windows forums just have hundreds of questions.
    As for the OS X forums, I wouldn't know, I'm too poor.

  2. #2
    Join Date
    Nov 2007
    Location
    Newry, Northern Ireland
    Beans
    1,258

    Re: How to launch commands in a separate Screen session via a bash script at startup?

    I think I can explain why it is happening, but I'm not sure how to work around it...

    A Bash script is a sequential list of commands, executed one after the other (very oversimplified, but go with it). What is happening is that the screen session is opened and a new Bash shell is launched inside it. However, the original Bash script is still running on the parent shell, and is waiting for the previous command to finish before executing the rest of the commands in the script. While the screen session and it's child Bash shell is active, the original script will not carry on.

    I'm not sure how you'd get around it, my first idea of starting the screen session backgrounded and then reconnecting to it using screen -r did not work when I tested it, I'll do some more Googling to see if there is a way to make this work.
    Can't think of anything profound or witty.
    My Blog: http://gonzothegeek.blogspot.co.uk/

  3. #3
    Join Date
    Apr 2007
    Beans
    2,578
    Distro
    Ubuntu

    Re: How to launch commands in a separate Screen session via a bash script at startup?

    This may help: http://ubuntuforums.org/showthread.php?t=1545643
    I guess you want the commands to run in the screen session you open. For such a case, the thread suggest
    Code:
    screen -dm -t title1 bash -c 'command1 ; command2 ; command3'
    You could replace the part after -c with the name of a script instead of a series of commands.

  4. #4
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    531
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to launch commands in a separate Screen session via a bash script at startup?

    Or just schedule them separately.

    Or issue the screen command with the nohup (no hangup) and & (run in background) command.

    I call screen sessions directly from crontab rather than running a script to start the screen.

    LHammonds

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •