Need help with simple startup bash script in CentOS

Hi guys,

I am very new to linux, so please bear with me.

I need a simple script (bash / .sh) to start 2 programs at server startup. Both programs should run in a detached screen of their own.

So basically:
1) start a detached screen with Program A running in it
2) start a new detached screen with Program B running in it

I have it already set up that it runs a 'start.sh' script on startup - so that part works. I just need the script itself.

I've tested a bunch of things that I've found on the internet, but nothing really works.

My latest test is this:

#!/bin/bash
screen -dmS "minecraft" sh -c 'cd  /root/lastcrafters; ./MCMA2_Linux_x86_64' &
screen -dmS "teamspeak" sh -c  '/root/lastcrafters/teamspeak/ts3server_startscript.sh start; exec bash' &

Each of the 2 commands work flawless when copy/pasted into Putty. But for some reason in the startup script they dont always work properly. Sometimes it works fine and both programs start as wanted. Sometimes only 1 of the 2 programs will start, and sometimes one of the programs will start doubled (once with a screen and once without a screen).

I have absolutely NO idea why this is. I have tried a sleep command between the 2 lines, to give it some time or something, but that didnt work either.

The 'exec bash' in the 2nd command is to keep the screen from closing, because teamspeak doesnt do anything in the screen and thus the screen would close from inactivity.

The 1st command doesnt need this, as Minecraft keeps spitting out things in the screen anyways.

I appreciate ANY and all help. Thank you for your time.

P.S.: I'm also open to any other/better way to get my goal accomplished. However, as I am completely new to linux, please explain thoroughly what I would have to do etc.

Times out?

echo $TMOUT

Please show the output of that command.

For starters, is there a reason you cannot login 3 times or must both of these commands run from the same parent process?

  login - cmd1  (no trailing &)
  login - cmd2  (no trailing &)
  login - play minecraft

As opposed to

                 login
                    |
      -----------------------------------------------------------
      ||                         ||                                   ||
    cmd1 &                    cmd2 &                                minecraft

You can login to separate, new, and unrelated processes as many times as needed in Linux. Normally there is point to doing that.

Where did you get the instructions to do this ? From the website or some other source.

If the server has a GUI (X with any DE - Desktop Environment or WM - Window Manager), it could be quite easy...

First locate, their desktopfiles ('Similar' to desktoplinks in Windows (it droped (plain-)text-links back around 1995):

Lets say your filemanager is "nautilus", start it as root to look for the links:

su -c "nautilus /usr/share/applications/"

Once you found minecraft and ts-server, place (copy-paste) those 2 files in "/etc/xdg/autostart", as the browser was started as root, there should be no problem doing so...

And in theory, you should be able to restart and they should get started on boot (to gui).

hth