Sean L. YoungStudio tools
Step 4 · Check & launch

Cron Job Builder

Set up tasks that your web server runs by itself on a schedule, such as nightly backups or a check that the site is working, without knowing any Linux. Choose a task, say when in plain words, and copy the result into cPanel.

What it's for

A cron job is a task the web server runs on a schedule, whether anyone is watching or not: back up the data every night, check the site every hour, send reminder emails every morning. cPanel has a Cron Jobs page for them, but it expects a timing code like 30 2 * * 1 and a Linux command.

The Cron Job Builder writes both for you, explains every part, shows exactly when it will run, and tells you where to paste it.

Your server settings

Fill these in once; they're kept in this browser. Click Your server settings to change them later.

  • cPanel username: under General Information in cPanel, as Current User. Your home folder is /home/ followed by it.
  • Website folder: almost always public_html.
  • Website address: used by the site check.
  • Your time zone and your server's time zone: so "3:00 a.m." means 3:00 a.m. on your clock. Many servers run on UTC. Not sure? See the next section.
  • PHP program: /usr/local/bin/php on most cPanel hosts.
Find the server's time zone

Choose the task Check the server's clock, add it in cPanel, and wait 15 minutes. Open server-time.txt in your home folder in File Manager: it shows the server's time zone, such as CST (UTC-0600). Choose the matching zone in your settings, then delete the job and the file.

The tasks

  • Back up data folders: every night, packs the folders where the site keeps its data (form answers, uploads, a SQLite database) into one dated file in a backups folder in your home folder, outside the website, so nobody can download it. Older backups are deleted after the number of days you choose.
  • Back up the website files: every week, the whole website folder, leaving out any folders you list. Kept for 2, 4 or 8 weeks.
  • Check the site is working: opens the pages you list, and if one doesn't answer properly, emails you which page and what it answered, such as 500 (an error in the code) or 000 (no answer).
  • Run a PHP script: for scripts that send reminders, tidy up or make reports. It runs from the script's own folder, so its includes are found.
  • Check the server's clock: finds the server's time zone, as above.
  • Write my own: any command, such as one from a plugin's instructions. The % signs that cron needs escaping are handled for you.
Keep a copy off the server

Backups on the same server don't help if the server itself fails. Every month or so, download the newest files from the backups folder in File Manager and keep them on your computer.

When it runs

Choose every few minutes, every hour, every day, every week or every month, and the time on your own clock. The result shows the time on the server's clock too, and Next 5 runs lists exactly when it will happen.

Night-time is best for backups, when few people use the site. Many shared hosts don't allow jobs more often than every 15 minutes.

If your time zone and the server's change for daylight saving time on different dates, a note explains that the job runs an hour earlier or later by your clock for part of the year. For backups and checks that doesn't matter.

Email

cPanel emails you whatever a job prints. Set the address once, under Cron Email at the top of the Cron Jobs page.

  • Only if something goes wrong (the default): the tasks print nothing when all is well, so you only hear about problems.
  • Every time: adds a short "done" message, handy for the first few days.
  • Never: throws all output away. You won't hear about failures either.

Adding it in cPanel

  1. Open Cron Jobs in cPanel (under Advanced).
  2. The first time, enter your email under Cron Email and click Update Email.
  3. Under Add New Cron Job, leave Common Settings alone and copy the five boxes (Minute, Hour, Day, Month, Weekday) into the matching boxes. Click a box in the builder to copy it.
  4. Click Copy next to the command and paste it into Command.
  5. Click Add New Cron Job. It appears under Current Cron Jobs, where you can edit or delete it.

On a server without cPanel, use Copy as one line and add it with crontab -e.

Explaining a cron line

The Explain a cron line tab turns any cron line into plain words: from a tutorial, a plugin's instructions, or a job already in cPanel. It explains each part of the command, lists the next 5 runs in your time, and warns about:

  • commands that delete files (rm), where a wrong path can delete your site
  • jobs that run more often than shared hosting allows
  • % signs that cron would misread
  • programs named without their full path
  • output thrown away, so you'd never hear about failures

Questions

Does this tool run the jobs?

No. A web page only runs while it's open; the server runs cron jobs. This tool writes the job, and cPanel runs it.

How do I restore a backup?

In File Manager, find the file in backups, choose Extract, and extract it to a new folder. Then copy back only what you need. Don't extract over the live site.

Can it back up a MySQL database?

Not yet as a ready-made task. Most cPanel hosts also include automatic backups under Backup or JetBackup; check what yours keeps.

Is anything sent to a server?

No. Your settings and jobs stay in this browser.