Crontab for linux commands and crontab for linux commands

Source: Internet
Author: User

Crontab for linux commands and crontab for linux commands
Cron is a built-in service in Linux. Run the following commands to start, view, and disable the service.

Service cron start // start service cron stop // close service cron restart // restart service cron reload // reload and configure service cron status // view service status
The cron global configuration file is in the/etc directory:
Cron. d/The system automatically and periodically performs the task cron. daily/task cron executed once a day. hourly/the cron task executed every hour. monthly/the cron task executed once a month. weekly/a task executed once a week. crontab specifies the task to be executed at the specified time.

User cron configuration file:

Each user has his own cron configuration file, which can be edited through crontab-e. Generally, after the cron configuration file is saved and exited, the system automatically stores the file in the/var/spool/cron/crontabs/directory. The file is named after the user name.


Crontab command format:

crontab [ -u user ] filecrontab [ -u user ] [ -i ] { -e | -l | -r }
Parameter description:
-U user: used to set the crontab service for a user. For example, "-u ixdba" indicates to set the crontab service for the ixdba user. This parameter is generally run by the root user. File: file is the name of the command file. It indicates that file is used as the task list file of crontab and is loaded into crontab. If this file is not specified in the command line, the crontab command accepts the commands typed on the standard input (keyboard) and loads them into the crontab. -E: edit the contents of a user's crontab file. If no user is specified, the crontab file of the current user is edited. -L: displays the contents of a user's crontab file. If no user is specified, the contents of the current user's crontab file are displayed. -R: deletes the crontab file of a user from the/var/spool/cron directory. If no user is specified, the crontab file of the current user is deleted by default. -I: A confirmation prompt is displayed when the user's crontab file is deleted.


Meaning of the crontab file:
In the crontab file created by the user, each row represents a task, and each field in each row represents a setting. Its format is divided into six fields. The first five fields are time sets, the sixth part is the command segment to be executed. The format is as follows:
minute   hour   day   month   week   command
Where:
Minute: minute. It can be any integer from 0 to 59. Hour: indicates the hour, which can be any integer from 0 to 23. Day: indicates the date, which can be any integer from 1 to 31. Month: represents the month, which can be any integer from 1 to 12. Week: the day of the week. It can be any integer from 0 to 7. Here 0 or 7 represents Sunday. Command: the command to be executed. It can be a system command or a script file compiled by yourself.
Crontab file format



You can also use the following special characters in the preceding fields:

Asterisk (*): represents all possible values. For example, if the month field is an asterisk, this command is executed every month after the conditions of other fields are met. Comma (,): values separated by commas can be used to specify a list range. For example, the following is a hyphen (-) in "1, 2, 5, 7, 8, 9 (-): you can use the middle bars between Integers to represent an integer range. For example, "2-6" indicates "2, 3, 4, 5, 6" forward slashes (/): You can use a forward slashes to specify the interval of time, for example, "0-23/2" indicates execution every two hours. At the same time, the forward slash can be used with the star number, for example, */10. If it is used in the minute field, it indicates that the execution is performed every ten minutes.

Note:
The script executed in the crontab file must be written to the absolute path.
When other environment variables are used in script execution, use the source command to introduce the environment variables.
In the crontab file, "%" indicates a line break. Escape if necessary.



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: info-contact@alibabacloud.com 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.