0

I run my minecraft server in a screen and I have a script set up to restart the server via crontab every night at 3 am.

restart.sh:

#!/bin/sh
echo "Letting people know that the server is going to restart...."
screen -R mc -X stuff "say Server is restarting in 1 minute! $(printf '\r')"
sleep 30s
screen -R mc -X stuff "say Server is restarting in 30 seconds! $(printf '\r')"
sleep 20s
screen -R mc -X stuff "say Server is restarting in 10 seconds! $(printf '\r')"
sleep 5s
screen -R mc -X stuff "say Server is restarting in 5 seconds! $(printf '\r')"
sleep 1s
screen -R mc -X stuff "say Server is restarting in 4 seconds! $(printf '\r')"
sleep 1s
screen -R mc -X stuff "say Server is restarting in 3 seconds! $(printf '\r')"
sleep 1s
screen -R mc -X stuff "say Server is restarting in 2 seconds! $(printf '\r')"
sleep 1s
screen -R mc -X stuff "say Server is restarting in 1 second! $(printf '\r')"
sleep 1s
screen -R mc -X stuff "stop $(printf '\r')"
sleep 15s
screen -R mc -X stuff "bash start.sh $(printf '\r')"
echo "Done"

This code works perfectly when I run it myself. It sends all the messages in the chat and then restarts but no matter how hard I wish, crontab just will not run it.

This is the code I have in the minecraft users crontab:

0 3 * * * /home/minecraft/server/restart.sh
  • Back to basics: Is restart.sh executable? – user535733 Feb 15 at 1:45
  • have you restarted cron service? Have you tried to set it work every minute? Make one echo in a file at start echo something > /your/path/file – Gryu Feb 15 at 1:51
  • $ ./restart Letting people know that the server is going to restart.... ./restart: 3: screen: not found ./restart: 5: screen: not found – Gryu Feb 15 at 1:53
  • Maybe there're errors with your screen -R mc -X stuff command when you run it using cron, but cron does not show them. – Gryu Feb 15 at 1:58
  • @Gryu this is because you don't have a screen named "mc" like i do, if you create a screen called "mc" and try running it again it should not give these errors – ashleyjustjoined Feb 15 at 2:31

Your Answer

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

Browse other questions tagged or ask your own question.