I have been working on creating a shell script for a while, browsing various forums including this one, and using all sorts of search terms with no luck. I hope I am not creating a duplicate question.

We have a game server and we have to initialize screen manually after a reboot or a crash, but would like to pack our few commands into one script to lower the downtime. What I would like to do is to make a script that creates a screen session, switches to it, and executes the shell script within the new session.

I have tried the code below in the shell script.

screen -S tf2

When I execute the script, it creates the screen 'tf2' and enters the session as I wanted. The server does not start where I wanted it to however, it boots up outside of the screen session where I executed it. We need it to be inside the screen session so that our game server can be online without anyone attending the terminal.

I am not the best with shell scripts yet but I am willing to learn, am I doing something wrong? Is there another way I should be going about this?


As stated in SYNOPSIS of man screen if you want to run a command in screen it needs to be appended to the command issuing screen. So in your case it would look like

screen -S tf2 ./startserver.sh

Yet as I do not know if your shell-script is in the working directory of screen, It is more clever to do this

screen -S tf2 /full/path/to/startserver.sh
| improve this answer | |
  • This helped a lot, it worked like a charm. I was running this in the working directory of the script I was attempting to execute. Thank you! – S3ntri Nov 29 '16 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.