Cron Jobs - What? Why? How?

What are cron jobs?1

Cron jobs are, at a very atomic level, your servant. You ask them to do something at specific intervals of time or at a specific time or date or day and they do it accordingly.

Now as this servant is not artificially intelligent you have to line-by-line teach it what to do, for which you have to write scripts for the cronjob to execute.

Why should anybody be using cron jobs?

How to cron?

Like all cool things, this one too has to be done using the terminal on your *nix system. The name of the program that lets you access and change the jobs is crontab. The two basic functions2 of crontab are -

Format of a cron job

* * * * * path_to_script
* * * * * /usr/bin/php path_to_php.php
* * * * * /usr/bin/python path_to_php.py

There are 5 specifiers of different units of time followed by path to a file which should be executed by the job.The specifiers are - from tuts+

I’ll do a follow up post which will be more detailed and will have some example cron scripts which I’ve used in real life projects. Till then you can easily generate the time specifiers using this bomb website called crontab.guru

  1. Formal Definition - The software utility Cron is a time-based job scheduler in Unix-like computer operating systems. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. ↩︎

  2. These are one of many options that crontab provides, but these are enough for basic use. ↩︎

.