How to Add Cron Jobs

SpinupWP automatically configures a cron job for every site on every server. These cron jobs can be easily managed within SpinupWP on the Cron tab for that site.

If you need to add cron jobs to your server beyond the scope of these site-based processes, you have a few options.

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:

  1. First, SSH to your server as the site user for the site you want to add the cron job to
  2. Enter the command crontab -e to bring up the cron job editor
  3. 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.
  4. Add your cron command on a new line
  5. Save the crontab file and exit. With Nano, this is Ctrl/Cmd + X, then Y.

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/turnipjuice.media/files/; sh example-script.sh >/dev/null 2>&1

Please notice the #Ansible: <your_domain> comment in the site’s crontab. SpinupWP uses this comment to identify the WordPress cron for this site. The line below this comment is managed by SpinupWP and any changes made to this line will be overwritten. If this comment isn’t found, a new cron entry with this comment above it will be added to the crontab by SpinupWP when a site’s cron is toggled on or off. SpinupWP will leave all other cron entries alone.

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.

  1. SSH to your server as the sudo user
  2. Enter the command sudo crontab -u root -e
  3. You will be asked for your sudo user password, enter it now
  4. 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.
  5. Add your cron command on a new line
  6. Save the crontab file and exit

Up Next

Beware that when multiple sites’ cron processes overlap, it can cause resource bottlenecks, slowing down your site. Editing your cron intervals can l combat this problem.

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 ⤵️