Sunday, February 3, 2008

Time Based Job Scheduling with Cron

Cron is a time based scheduling service available in Unix and its variant. Cron was derived from Greek language "chronos" that means time.

In Ubuntu, cron is multi user, and every user in the system could schedule any job using cron with simple command "crontab -e". This command will invoke the default text editor to add/remove new job.

Below is one example in which I want to ask my computer to reindex my hard disk content using recoll (via "recollindex" command line) every 2:00AM every day, and log every single message to "/tmp/cron-recollindex" :
crontab -e
0 2 * * * recollindex > /tmp/cron-recollindex 2>&1

In Ubuntu crontab -e will invoke nano. To change it with your favorite editor, use the following command (just replace "vi" with your favorite one) :

EDITOR=vi && crontab -e
If you want a permanent changes on the editor, put the following line inside your .bashrc file :

export EDITOR=vi

No comments: