Could someone tell me how to restart a process every 4 hours using crontab? I have a Starbound server running (which is a game like Terarria which recently came out) and it's taking a lot of resources, so I'd like to kill the process then start it back up every 6 hours.
What I think I would need to do in crontab is:
kill -9 | grep starbound_server cd /home/steam/starbound/linux64 && screen -S starbound -d -m ./launch_starbound_server.sh
But I am not sure about this and don't understand the time thingy either.
I hope someone can help me :)
To run a cron job at every system boot, add a string called @reboot to the end of the task list. The job defined by this string runs at startup, immediately after Linux reboots. Note: Always use the full path to the job, script, or command you want to run, starting from the root.
No. As long as you use the crontab -e command to edit the file, when you save it, you'll get a 'New Crontab Installed' message. That's it.
Cron jobs are tasks that run automatically following some predefined schedule.
1 Answer. No. Come and join Linux training to gain great knowledge.
crontab works like this.
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
So if you want to run your script every minute on 4 hour intervals, you'd have to add this line to crontab file.
* */4 * * * user-name command to be executed
To run your script once every 4 hours (on the zero minute), you'd have to add this line to crontab file.
0 */4 * * * user-name command to be executed
Edit ( Answer to comment ):
Yes, I believe this is correct, but as myself I usually do separate file for this, for example, script.sh to keep things clean.
For example with contents:
#!/bin/sh
# Kill 1
screen -X -S | grep starbound kill
# Kill 2
kill -9 | grep starbound_server
# Change directory
cd /home/steam/starbound/linux64
# Start the server again
screen -S starbound -d -m ./launch_starbound_server.sh
You can save it to the location you like and use:
chmod +x yourcript.sh
to make it executable, and then add it to crontab.
Provided that you have installed the starbound server start script in /etc/init.d
http://www.bubblews.com/news/1749423-starbound-server-start-script
And you named it starbound.sh
Then, add a line in your /etc/crontab
like this:
0 /4 * * * root /etc/init.d/starbound.sh restart
(NOTE: this is in case the starbound server is started by root
: check that the server itself drops its priviledges upon starting if it doesn't need them)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With