crontab is a tool for configuring scheduled tasks. It also maintains each user’s own crontab files.

Options

Here are some options for crontab command:

Option Description
-u user Modify the specified user’s crontab.
-e Edit user’s crontab.
-l List user’s crontab.
-r Remove user’s crontab.
-i User confirmation is required to perform a delete operation.

Crontab File

Job Definition

Time and Date Fields User name Command
* * * * * [root] wall ‘Broadcast message’ [Without receiving mail: > /dev/null or &> /dev/null]

Time and Date Fields

Field 1 Field 2 Field 3 Field 4 Field 5
* * * * *
Minute Hour Day of month Month Day of week
0-59 0-23 1-31 1-12 or Jan-Dec 0-7 or Mon-Sun

Time and Date Nicknames

Nickname Definition Actual meaning
@hourly 0 * * * * Run hourly.
@daily 0 0 * * * Run daily.
@weekly 0 0 * * 0 Run weekly.
@monthly 0 0 1 * * Run monthly.
@annually or @yearly 0 0 1 1 * Run annually.
@reboot Run after reboot.

Time and Date Fields Utilization

Field Description
N Specifies a value within the valid range value of a field.
* All values within the valid range value of a field.
N,N,N Multiple values within the valid range value of a field.
N-N Range values within the valid range value of a field.
*/N The number that can be divided by the maximum value of a field.

Examples

Check Whether Crond is Running

1
systemctl status crond
img

Install cronie If It Has Not Been Installed Yet

1
yum install cronie

Check Crontab Configuration

1
cat /etc/crontab
img

Here are some configuration fields in /etc/crontab file:

Field Description
SHELL Shell to be used by crontab.
PATH The path to the command executed by crontab, and if the command is not in these directories, the full path needs to be specified.
MAILTO The user who will receive the message after the crontab command has been executed.

Run Command Every Minute

1
2
3
# > /dev/null means don't send email to user, unless there is an error
crontab -e    # This will open the job definition file in editable mode
*/1 * * * * /usr/bin/wall 'This message is broadcast every minute.' > /dev/null

If this is the first time a crontab is created, the following information will be output after the creation:

img

After few minutes:

img

List Scheduled Jobs

1
crontab -l
img

Delete Scheduled Jobs With Confirmation

1
2
3
crontab -l
crontab -ri    # At this stage: Input y or yes and press enter
crontab -l
img

References CRONTAB(1), CRONTAB(5)

Buy me a coffeeBuy me a coffee