Tuesday, July 31, 2007

Using crontab scheduler

Crontab is a tool for scheduling tasks for the computer to run. It will automate the jobs that needs to be done but will be difficult to be done by human because of time limitation. There are only 4 options for crontab which are -u, -e, -l and -r and the usage is described below:
  • crontab -l - list all the crontab on standard output
  • crontab -e - edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables
  • crontab -r - remove the current crontab
  • crontab -u - specify the user
    • example: $ crontab -u username -l - this command will list the crontab belongs to the username
Crontab is set by running the crontab -e command and add the necessary time and the command to be run on that particular time. Crontab scheduling format are as below:

* * * * * command to be run

1st * is for minutes (0-59)
2nd * is for hour (0-23)
3rd * is for day of month (1-31)
4th * is for month of year (1-12)
5th * is for day of the week (0-7) where 0=Sunday and 7=Sunday

Example:
To backup your pc using rsnapshot everyday at 7.30 a.m.;
  1. $ crontab -e
  2. 30 7 * * * /usr/local/bin/rsnapshot daily
  3. save your crontab setting





No comments:

Post a Comment