Scheduling Tasks With Cron

Adding user tasks

To add a task to a user’s cron jobs, use the command crontab -e. You can view a user’s crontab with crontab -l. Use man crontab for more information.

The format for the crontab file is:


  #  +---------------- minute (0 - 59)
  #  |  +------------- hour (0 - 23)
  #  |  |  +---------- day of month (1 - 31)
  #  |  |  |  +------- month (1 - 12)
  #  |  |  |  |  +---- day of week (0 - 7 with Sunday=0 & 7)
  #  |  |  |  |  |
  #  *  *  *  *  *  command to be executed

An asterisk indicates that the job is to run every minute, hour, etc. To help you remember the format, you can paste these comments the top of your crontab file.

Examples:
This will run a script every 2 minutes:

*/2 * * * * /path/to/script

This will run a script on the 1st and 15th of every month at 4am:

00 4 1,15 * * /path/to/script

Adding system tasks

For system tasks, you can also put a script in /etc/cron.[hourly, daily, weekly, monthly]. You can find examples in /etc/cron.daily.

Find more information in the Redhat docs

Meta