Sunday, March 29, 2009

Easy Crontab Howto

Here is a quick howto on crontab, crontab is a text file that has a list of commands that are to be run at specified times, the command and their run times, are controlled by the cron daemon and are executed in the system's background, the system maintains a crontab for each user, you will be able to edit the crontab file by using the -e switch when using the crontab command like so:

$ crontab -e

If this is the first time you have used crontab the list may be blank.

All you need to now to use crontab and schedule a command is when you will run it and when you will want it to run

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

An example entry would be

* 10 * * 1,3,5 /usr/bin/updatedb

The entry above will execute updatedb on 10am every monday, tuesday, friday, after saving the file you can view the crontab entry by using the -l option

$ crontab -l

Thats it.



Tech Blog Quick List of howto's:

2 comments:

Anonymous said...

You may want to check the syntax on your example. If I'm not mistaken, your entry actually says to execute updatedb every minute from 10:00am to 10:59am, not just 10:00am. I believe the first entry should be 0 instead of *.

Anonymous said...

Also, it will execute updatedb on mondays, wednesdays and fridays. (Not on tuesday :))

For suggestion and concerns E-mail