Search:  
Gentoo Wiki

Crontab

Contents

What is Cron

The crontab command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. It reads a series of commands from standard input and collects them into a file also known as a "crontab" which is later read and whose instructions are carried out.

Generally, crontab uses a daemon, crond, which runs constantly in the background and checks once a minute to see if any of the scheduled jobs need to be executed. If so, it executes them. These jobs are generally referred to as cron jobs.

Requirements

User must be part of the 'cron' group to edit his/her cron, but does not need to be in that group to have a cron run as that user.

You can add users to the cron group as root using

# gpasswd -a me cron

Be careful when adding yourself to cron group via su. You need to log back in before the new group takes effect.

Displaying programmed events

To display the programmed events run the following command:

$crontab -l

The -l option causes the current crontab to be displayed on standard output.

Editing/Creating the Crontab

to setup a cron job to run as your user

$crontab -e

As another user (Must be done as root)

#crontab -u username -e

The Crontab Layout

File: crontab
# minute (0-59), 
# |     hour (0-23), 
# |     |       day of the month (1-31), 
# |     |       |       month of the year (1-12), 
# |     |       |       |       day of the week (0-7 with 0=7=Sunday). 
# |     |       |       |       |       command(s)
# |     |       |       |       |       |
  */5   *       *       *       *       fetchmail -aKv -m "/usr/bin/procmail -d %T" >/dev/null 2>&1

The slash in the first column means that the command fetchmail -aKv -m "usr/bin/procmail -d %T" >/dev/null 2>&1 will take place once every five minutes. Note that it is in the minutes column.

See Also

Retrieved from "http://www.gentoo-wiki.info/Crontab"

Last modified: Mon, 16 Jun 2008 04:47:00 +0000 Hits: 37,023