1

I apologise if this has been asked before but I am not sure how to question a search query for this. I am extremely new to linux and I have been learning as I go to solve issues.

I am trying to set up working cron jobs to restart a game server I am running.

Currently my crontab looks like this

#backup world as instructed by https://github.com/g1franc/SEDS-Setup
0 0 * * * /home/root/spaceengineers/start.sh backupworld
#close server
1 0 * * * /usr/bin/screen -S spaceengineers -X stuff "^C"
#close screen
2 0 * * * /usr/bin/screen -S spaceengineers -X stuff "^M"
#recreate server
3 0 * * * /home/root/spaceengineers/start.sh

Now on the backup world I get in my syslog file located at /var/log i get

May 24 00:00:01 SpaceEngineers CRON[1958]: (root) CMD (/home/root/spaceengineers/start.sh backupworld)
May 24 00:00:01 SpaceEngineers CRON[1957]: (CRON) info (No MTA installed, discarding output)

and that is also the same with the recreate server

May 24 00:03:01 SpaceEngineers CRON[2269]: (root) CMD (/home/root/spaceengineers/start.sh /usr/bin/screen -x spaceengineers)
May 24 00:03:01 SpaceEngineers CRON[2268]: (CRON) info (No MTA installed, discarding output)

The other commands work perfectly fine.

now before anyone questions why I have structured my code the way I have, its because the tutorial i was following says to start the server via ~/spaceengineers/start.sh -x spaceengineers and from what I have read i need to do /usr/bin/screen to access any screen commands in Cron

What am I doing wrong and what do I need to do to rectify my issues.

EDITED: Changed the crontab to match current contents on my server, issues remain the same

Pastebin of start.sh

http://pastebin.com/9QcWyqYF

  • 1
    The message about MTA is happening because CRON tries to send email on job completion. It can be safely ignored, unless you want the job output to be sent via email. Are the two problematic jobs actually running as expected? Do they do what you want? – boot13 May 23 '15 at 17:33
  • @boot13 Just rechecked and the backup script seems to be doing something now but the recreate server job is not doing anything – TheAngryBr1t May 23 '15 at 17:40
  • Can you add the relevant bits from the start scriot – fswings May 24 '15 at 0:24
0

Can you check the GNU screen syntax for this line:

3 0 * * * /home/root/spaceengineers/start.sh /usr/bin/screen -x spaceengineers

I would've expected something like:

3 0 * * * /usr/bin/screen -S spaceengineers -X stuff 'command with newline' 

However, using the -X means screen expects screen commands and not a script to run.

Therefore you need to use the screen stuff command as per this SU question

screen -S sessionname -X stuff 'command'`echo -ne '\015'`

Update

Try /bin/bash or wherever the Shell you use is located.

 3 0 * * * /bin/bash /home/root/spaceengineers/start.sh

Maybe add contents of start.sh to help debug.

You can find shell with the which command. Might have to sudo or be root to find out.

  • I have just removed the usr/bin/screen stuff as it is no longer needed. turns out the script is creating a screen by itself, I believe that to be when running a program through WINE. as I said I am learning on the fly. But with this stuff now removed the script is still not executing. the recreate server line now reads: 3 0 * * * /home/root/spaceengineers/start.sh The reason I have changed it to that is the backup script is working and its called the same way. have edited the question with the new crontab – TheAngryBr1t May 23 '15 at 23:18
  • In my crontab had to specify the Shell location. – fswings May 23 '15 at 23:41
  • I added /bin/bash after checking what shell I am using and making sure i had my Crontabs SHELL path set to SHELL=/bin/bash I am still not getting anywhere. I have made sure the shebang in the script is set correctly as well. UPDATE: Finally seeing in the syslog that it is trying to run commands. For the last 2 hours I wasnt getting anything in the log. May 24 00:03:01 SpaceEngineers CRON[2594]: (root) CMD (/bin/bash /home/root/spaceengineers/start.sh) It still is not actually creating the screen like it normally does if run manually, but i guess its a step forward. – TheAngryBr1t May 24 '15 at 0:22
  • The script may have to be modified so it uses absolute paths. – fswings May 24 '15 at 0:23
  • pastebin.com/9QcWyqYF here is pastebin of code – TheAngryBr1t May 24 '15 at 0:26
0

This command worked for me, though because one or more of the commands in my script required sudo, I had to set this up under the root user's cron :

17 2 29 1 * /usr/bin/screen -dmS $MYSESSIONNAME /bin/bash $FULLPATHTOMYSHELLSCRIPT $SHELLSCRIPTARG1 $SHELLSCRIPTARG2 ...

The key to getting screen working (and not just closing immediately when invoked by cron) is the -d argument, but the m probably helps too in some way/cases.

Below is the relevant snippet from the screen --help output

-dmS name Start as daemon: Screen session in detached mode."

-1

@daily /usr/bin/screen -dms aquaticscenery /ig.py && python ig.py

  • 5
    Can you explain this command? :) – bertieb Apr 19 '17 at 13:37
  • 1
    This may be a correct solution but please explain a bit more of how this solves the question asker's question – Eric F Apr 19 '17 at 16:11

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.