Cron jobs are quite simply a task that runs every time it is triggered by the clock. For example, I could create a script that creates a tarball of my website that runs every 4 hours.
In order to create a new cron job, we can issue the command crontab -e. This opens the cron job file into vi, allowing editing.
In order to start editing the file, press i to put you into insert mode.
We can then start adding entries.
a cron job line generally looks like the following:
* * * * * /path/to/yourscript.sh
Where each of the stars represent an increment of time:
Minute Hour Day Month Weekday
So, to create a job that runs once every 4 hours at the 0th minute, the line would be
0 */4 * * * /path/to/yourscript.sh
To explain this, we can say that everytime the minute hits 0, and we hit the fourth hour, on any day, month or weekday we will run the script.
If we wanted it to run every day at 11:55 we could set the line to:
55 11 * * * /path/to/yourscript
Once we have added the lines we need, press Esc to exit insert mode, and type :wq to save and exit the crontab.
Your changes will take effect immediately.
As an example, below is the line I use to backup my website into a tarball called bkup.tar:
0 */4 * * * tar -cf /home/philwcco/public_html/backup/bkup.tar /home/philwcco/public_html

