Answer the question
In order to leave comments, you need to log in
How to run a cron script?
Maybe I'm stupid. But I can't solve one problem. I made a Minecraft server for my son. The server, in principle, works stably, but my son (12 years old) likes to upload all sorts of "left" plugins and worlds. After that the server often crashes. I made a service script that starts, stops and restarts the server from /etc/init.d/minecraftpe:
/etc/init.d/minecraftpe start
/etc/init.d/minecraftpe stop
/etc/init.d/minecraftpe restart
#!/bin/bash
d=$(date +"%d/%m/%Y, %T")
/etc/init.d/minecraftpe status
if [ $? == 0 ]; then
/etc/init.d/minecraftpe start
echo "[ $d ] Restarting Minecraft" >> /var/log/minecraftpe.log
/etc/init.d/minecraftpe status
if [ $? == 0 ]; then
echo "[ $d ] Could not restart the server" >> /var/log/minecraftpe.log
else
echo "[ $d ] Server was restarted successfully" >> /var/log/minecraftpe.log
fi
else
echo "[ $d ] Running" >> /var/log/minecraftpe.log
fi
*/1 * * * * root /home/arik/pocketmine-new/keeprunning.sh
[ 29/08/2016, 20:13:01 ] Restarting Minecraft
[ 29/08/2016, 20:13:01 ] Could not restart the server
Answer the question
In order to leave comments, you need to log in
The question is closed. It was necessary to set absolute paths to programs. Specifically, /sbin/runuser instead of runuser.
If the script behaves differently when launched from the console and from under cron, it is most likely due to environment variables - PATH, etc.
Try setting the PATH in the script or, more radically, add the line at the beginning. ~/.profile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question