Linux – How to use crontab to start a screen session

crongameservergnu-screenlinux

I want to create a crontab entry so that it starts screen, starts a gameserver and detaches. This is for in case the server is rebooted and I want it to automatically start this for me.

0 0 0 0 0 (command)

should run upon startup.

It runs a shell file located at ~/cube/server.sh

Best Answer

Something like this should work. This example spawns a screen and runs "top":

screen -d -m top

In your crontab, as indicated, you'd want to do something like this:

@reboot /usr/bin/screen -dmS gameserver-screen /opt/mycoolgame/bin/gameserver

Of course, if the game server requires a "normal" environment set, you can get closer by:

@reboot (. ~/.profile; /usr/bin/screen -dmS gameserver-screen /opt/mycoolgame/bin/gameserver)