Linux crontab Command Syntax detailed

Source: Internet
Author: User

The purpose of the crontab command is to submit, edit, list, or drop a cron job.

1. Grammar

crontab [E [UserName] |-l [USERNAME] |-r [UserName] |-v [USERNAME] | File]

2. Description

The crontab command submits, edits, lists, or drops cron jobs. A cron job is a command that is run by a cron daemon at the scheduled interval of a rule. To submit a cron job, specify the crontab command with the-e flag. The crontab command invokes an editing session, allowing the creation of a crontab file. In this file, create entries for each cron. Each entry must be a format that the cron daemon can accept. For information about creating entries, see the crontab file entry format.

When the entry is created and the file is exited, the crontab command copies it to the/var/spool/cron/crontabs directory and puts it in a file whose name is the current user name. If a file named with a user name already exists in the Crontabs directory, the crontab command overwrites it.

Similarly, you can create a crontab file by specifying a file parameter. If this file already exists, the format must be required by the cron daemon. If the file does not exist, the crontab command invokes the editor. If the EDITOR environment variable exists, the command invokes the editor it specifies. Otherwise, the crontab command invokes the VI editor.

To list the contents of the crontab file, specify the crontab command and use the-l flag. To remove existing files, use the-R flag.

The optional UserName parameter can be used by the owner of the crontab file or by the root user to edit, list, drop, or verify the status of the cron job for the specified user. If the UserName is invalid, an error message is generated and the program exits. If the optional UserName parameter is not specified, this crontab flag is available to the root user and the current user.

3. Safety

Only the owners of the root and crontab files can use UserName after the-e,-L,-R, and-V flags to edit, list, drop, or validate the crontab files for the specified user.

4. Cron Daemon

The command and crontab file entries that this cron daemon runs are relative. If the output of the cron job is not redirected to standard output or standard error, the cron daemon notifies you by e-mail of any command output or error. This cron daemon does not run this job if an incorrect cron job is specified in the crontab file.

The cron daemon checks the crontab file only when the cron daemon is initialized. When the crontab file is changed with the crontab command, the message that indicates the change is sent to the cron daemon. This eliminates the overhead of checking for new or changed files at the scheduled interval of a rule.

5, control the use of crontab command

/var/adm/cron/cron.allow and/var/adm/cron/cron.deny files control which user can use the crontab command. The root user can create, edit, or delete these files. The entries in these files are the user login name, one name per line. If the login identity is associated with multiple login names, the crontab command takes the first login name in the/etc/passwd file, regardless of which login name is currently actually used. Also, to allow users to start a cron job, you should use the Chuser command to set the Daemon property in the/etc/security/user file to TRUE.

An example of the following about the Cron.allow file:

Root Nick Dee Sarah.

If the Cron.allow file exists, the crontab command is available only to users whose logon name appears in the file. The root login name must appear in the Cron.allow file if the file exists. The system administrator can explicitly stop a user by using the crontab command and listing the user's login name in the Cron.deny file. If only the Cron.deny file exists, a user with any name that does not appear in the file can use the crontab command.

If one of the following conditions is true, the user will not be able to use the crontab command:

Cron.allow files and Cron.deny files do not exist (only root users are allowed).

The Cron.allow file exists, but the user's login name is not listed therein.

The Cron.deny file exists and the user's login is listed.

If Cron.allow and Cron.deny files do not exist, only people authorized by Root can submit a job with the crontab command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.