Google
 

Linux Distro Counter

Welcome to Open Source Software and Linux Blog.

Hi, everyone!. I just created this blog to share knowledge about open source software and Linux. If you all have knowledge and info related to open source / Linux, please share or send me an email. Thanks ^_^

Friday, August 17, 2007

Job scheduler (Crontab) for Linux

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. Open terminal and type crontab -e
  2. In crontab area type; 30 7 * * * /usr/local/bin/rsnapshot daily
  3. save your crontab setting and exit

No comments: