Linux Help - What are Cron Jobs, Crontabs - Cron Tutorial Guide

this is a very good short tutorial i wrote about cron jobs when i was learning about linux and did not understand what cron was.

cron is a Linux system process that executes a script or a program at a determined time. To be able to use cron, you will need shell access into your server. You will also need a cron file, usually this is a text file you can create in the VI (Linux Editor), or NANO if you are a biginner like me. Once you have created the .cron file, you then use the crontab command to load the .cron file the calls the script.

For example, lets say I want to get a daily email of all the hits I got on my website at the end of the day, that would mean I would want stats.php (for example) to be run at 11:59 everyday and send the results to my email address. here are the steps to take:

1. First, create a cron file the looks like this:

 59 23 * * *  /path/to/cron/file

 type the following at the shell command prompt:

     step        type (bold mean what you actually type)

  1.          nano example.cron
  2.          59 23 * * * /path/to/cron/file
  3.             ( hit control + x )
  4.             Save Modified buffer? Y
  5.             File to Write: example.cron... hit return
  6.             ls then return
  7.            When you type ls, it will display the list of files, you should see example.cron

note:/path/to/this/file is the directory where the cron file to be executed is located

note: Use military time for the hour

2. now the you have created the cron file, execute the corntab command

3. execute the following command to list any jobs that are currently loaded int crontab

crontab -l


If none are listed, its ok to continue loading your cron job.

4. To execute load the cron job you created on step 1, type the following command:

crontab /path/to/example/file

 

5. Now execute the crontab -l command again and your cron job should be listed, otherwise, you did something wrong. try again.


 

To edit a cron job simple edit the example.cron file, then reload crontab with these cammands:

crontab -r (CAREFUL: this will remove example.cron or any other crons you may have) 

crontab /path/to/example.cron 

for more help, you can run the man crontab for more information.

 

8804 - Sat Feb 02, 2013 22:11:24