页面

2008-07-03

Schedule Job by cron

Use the front interface crontab (it is necessary to export the EDITOR environment variable firstly):
  1. List cron jobs: crontab -l
  2. Edit cron jobs: crontab -e
  3. Delete cron jobs: crontab -r
When invoking 'crontab -e', each line indicates one job, and the first five fields are time fields and the sixth field is the command (i.e. job and script) field. The time fields format:
minutes - 0-59
hours - 0-23
days of month - 1-31
months of year - 1-12
days of week - 0-6 (Sunday-Saturday)

Use '-' to indicate range for one time field, use ',' to separate a group of values for one time field, and use asterisk to indicate all possible value.
Examples:
  1. 15 * * * * my_job
  2. 0,15,30,45 8-17 * * 1-5 my_job
If you need to run a job periodically, use this:
*/10 * * * * my_job
It means running my_job every 10 minutes. Even use SSH to invoke crontab, the jobs arranged run perfect after reboot the system.

On ubuntu, crontab for root:
$ sudo -i crontab -e

Remark: If one specifies upper slot, e.g. hours, he had better specify the lower slot whenever possible, e.g. minute; a potential disaster example, * 2 * * * my_job, the item will run every minute of 2:00 every day. Do not worry about privilege: the default crontab privilege is of the user who runs crontab for editing (adding) item.


没有评论: