Wednesday, May 14, 2008

cron

Cron is the way you schedule tasks in Linux. It runs in the background and will execute the command you tell it to when you tell it to.

If this looks like I stole it from Linux Reality Episode 39, it is because I did. The show is great, but it is difficult to reference a podcast when you are trying to actually do something, so I have taken notes here.

Login as the user you want to run the cron job.
$crontab -e

If you want to use a different editor (nano) use the command
$EDITOR=nano crontab -e

The basic format for a crontab entry is as follows (separated by spaces)
minutes hours dayofmonth month dayofweek command
minutes range is 0-59
hours range is 0-23
dayofmonth range is 1-31
month range is 1-12
day of week range is 0-6, 0=Sunday
In order to for getmail to check mail every minute, add the following line:
* * * * * getmail
or, to check email every hour on the hour, add the following line
0 * * * * getmail
save and exit. See the section on text editors if you are not familiar with the vim text editor.

No comments: