How to Add Cron Jobs
A UI to configure cron jobs right from the SpinupWP dashboard is on the roadmap, but if you are looking to add cron jobs for your sites right now, then here are the manual steps you need to take.
Non-Root Cron Job
If the scheduled command doesn’t need to be run as the root user, it should be set up to run as a site user:
- First, SSH to your server as the site user for the site you want to add the cron job to
- Enter the command
crontab -e
to bring up the cron job editor - If this is the first time you have done this, the command will ask you to ‘Select an editor’. Nano is the easiest editor, so enter ‘1’ to select it.
- Add your cron command on a new line
- Save the crontab file and exit. With Nano, this is
Ctrl/Cmd + X
, thenY
.
If you need help generating your cron command and configuring the syntax for the schedule, then this crontab generator can help.
For example, this command runs a bash script in the root of a site every 12 hours and doesn’t save or send output:
* */12 * * * cd /sites/mysite.com/files/; sh example-script.sh >/dev/null 2>&1
Root Cron Job
If the scheduled command requires root permissions then you will need to add the crontab line to the root user. You will need to have already created a sudo user on the server and recorded the password somewhere.
- SSH to your server as the sudo user
- Enter the command
sudo crontab -u root -e
- You will be asked for your sudo user password, enter it now
- If this is the first time you have done this, the command will ask you to ‘Select an editor’. Nano is the easiest editor, so enter ‘1’ to select it.
- Add your cron command on a new line
- Save the crontab file and exit
Up Next
Beware that when multiple sites’ cron processes are running at the same time, it can cause resource bottlenecks, slowing down your site. Staggering your cron jobs will combat this problem. SpinupWP customers won’t have to deal with this for long as automatically staggering WordPress cron jobs is on our roadmap.
SpinupWP takes care of the nitty gritty for you, allowing you to spin up your own Ubuntu server in minutes and serve your WordPress sites lightning fast. See for yourself with our 7 day free trial ⤵️