The crontab of Linux commands

Source: Internet
Author: User

Cron is a built-in service for Linux. You have the following command to start, view, and close this service.
Service cron start//           start service cron stop            //Shutdown Services service cron Restart        //Restart service cron Reload         // Reload Configuration service cron status//View services status
Cron Global configuration file in/etc directory:
cron.d/System Automatic recurring tasks cron.daily/tasks performed once a day cron.hourly/tasks performed once per hour cron.monthly/tasks performed once a month cron.weekly/ Tasks performed once a week crontab tasks performed at a specified time

User cron configuration file:

Each user has their own cron profile, can be edited through CRONTAB-E, generally we edit the user's cron profile saved exit, the system will automatically be stored 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 a user's crontab service, for example, "-u ixdba" means to set IXDBA user's crontab service, this parameter is usually run by the root user. File:file is the name of the command file, which indicates that file is the Crontab task list and loaded into crontab. If this file is not specified on the command line, the crontab command will accept the commands typed on the standard input (keyboard) and load them into crontab. -E: Edits the contents of a user's crontab file. If you do not specify a user, the crontab file for the current user is edited. -L: Displays the contents of a user's crontab file, or displays the contents of the current user's crontab file if no user is specified. -r: Deletes a user's crontab file from the/var/spool/cron directory and, if no user is specified, deletes the current user's crontab file by default. -I: Give a confirmation prompt when deleting a user's crontab file.


What the crontab file means:
In the crontab file created by the user, each line represents a task, each field of each row represents a setting, its format is divided into six fields, the first five is the time setting segment, and the sixth paragraph is the command segment to execute, in the following format:
Minute   hour   Day   month   Week   command
which
Minute: Represents minutes, which can be any integer from 0 to 59. Hour: Represents the hour, which can be any integer from 0 to 23. Day: Represents a date, which can be any integer from 1 to 31. Month: Represents the month, which can be any integer from 1 to 12. Week: Represents the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday. Command: The commands to execute can be either system commands or script files that you write yourself.
Crontab file format



In each of these fields, you can also use the following special characters:

Asterisk (*): represents all possible values, such as the month field if it is an asterisk, the command action is executed monthly after the constraints of other fields are met. Comma (,): You can specify a list range with a comma-separated value, for example, "1,2,5,7,8,9" in Bars (-): You can represent an integer range with a middle bar between integers, such as "2-6" for "2,3,4,5,6" forward slash (/): You can use a forward slash to specify the interval frequency of the time, for example "0-23/2" means to execute every two hours. A forward slash can be used with asterisks, such as */10, if used in the minute field, which means that it executes every 10 minutes.

Precautions :
The script executed in the crontab file is to write an absolute path.
When script execution uses other environment variables, the environment variables are introduced through the source command.
In the crontab file, "%" is a special meaning that represents a newline. If necessary, you need to escape it.



The crontab of Linux commands

Related Article

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.