+254725682556 +254725052660 info@ziprof.co.ke
Client Area

General Knowledge

What Is a Cron Job and How Does It Work?

A cron job is a task that your hosting server runs automatically at times you choose, instead of you having to log in and run it yourself. You tell the server what to run and how often, and it handles the rest in the background. The name comes from cron, the scheduling system built into the Linux servers that most web hosting runs on.

Why would you use a cron job?

Cron jobs are useful for anything that needs to happen repeatedly without you remembering to trigger it. Common examples include:

  • Taking an automatic backup of your website or database on a set schedule.
  • Clearing a cache folder so your site doesn't fill up with old temporary files.
  • Running a script that sends scheduled emails or reminders to customers.
  • Checking for and applying updates to an application at a quiet time of day.
  • Deleting old log files or session data so they don't eat into your disk space.

If a task on your website needs to repeat on its own, on a schedule, a cron job is almost always how it's done.

How the schedule works

A cron schedule is written as five fields, in this order: minute, hour, day of the month, month, and day of the week. Each field can be a specific number, a range, or an asterisk (*), which stands for every value in that field.

A few examples make this easier to read:

  • 0 2 * * * runs once a day, at 2:00 AM.
  • */15 * * * * runs every 15 minutes, all day, every day.
  • 0 0 1 * * runs once a month, at midnight on the 1st.
  • 0 9 * * 1 runs every Monday at 9:00 AM.

You don't need to memorize this format. Both cPanel and DirectAdmin give you simple dropdown menus for every minute, every hour, once a day, and so on, and build the underlying schedule for you.

Cron jobs run in your server's time zone, which may not match your local time in Kenya. If a task needs to run at a specific local time, check your server's time zone first and adjust the hour you schedule accordingly.

Things to keep in mind

  • Running a heavy script too frequently (every minute, for example) can use up server resources unnecessarily. Only schedule a task as often as it genuinely needs to run.
  • Cron jobs usually send an email notification with the output each time they run, which can flood your inbox. Most control panels let you turn this off or redirect it to a specific address.
  • Double-check the exact file path to the script you want to run. A cron job with a wrong path will simply fail silently rather than show you an error on screen.

If you're ready to set one up, see the step-by-step guides for setting up a cron job in cPanel or setting up a cron job in DirectAdmin, depending on which control panel your hosting account uses.