LINUX/ETC/CRON.D function (turn from scheduled task crontab CRON.D)

Source: Internet
Author: User

Original link: http://huangfuligang.blog.51cto.com/9181639/1608549

First, CRON.D increase the timing task

When we want to increase the overall planning task, one way is to modify/etc/crontab directly. However, this is not generally recommended, and the/ETC/CRON.D directory is created to solve this problem.

For example, to add a scheduled backup task, we can do this: Create a new file backup.sh in the/ETC/CRON.D directory with the following:

# m H Dom Mon Dow user command

* 1 * * * root/sbin/mon_zetc_logtar.sh

When the cron process executes, it automatically scans all files in that directory and executes subsequent commands according to the time settings in the file.

Cron execution, that is, to read three local configuration files: One is/etc/crontab, the second is the/ETC/CRON.D directory of all files, and three is the profile of each user

Second, the control of the use of cron

/etc/cron.allow and /etc/cron.deny files are used to limit the use of cron. The two formats used by the control file are one user per line. None of the two files allow spaces. If the control file is modified, the cron daemon (crond) does not have to be restarted. Using control files is read every time a user adds or deletes a cron task.

The root user can always use cron regardless of what is specified in the control file.

If the cron.allow file exists, only the users listed in it are allowed to use cron, and the cron.deny file is ignored.

If the cron.allow file does not exist, all users listed in Cron.deny are prohibited from using cron

Third, start or close

Since Cron is a built-in service for Linux, you can start and shut down this service in the following ways:

/sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration

Iv. introduction of Crontab

Each line in the/etc/crontab file represents a task, in the form of:

Minute hour day Month DayOfWeek command

minute-minutes, any integer from 0 to 59

    • hour-hours, any integer from 0 to 23

    • day-any integer from 1 to 31 (if a month is specified, it must be a valid date for that month)

    • Month-month, any integer from 1 to 12 (or use the English abbreviations of the month such as Jan, Feb, etc.)

    • Dayofweek-week, any integer from 0 to 7, where the 0 or 7 represents Sunday (or use the English abbreviations of the week such as Sun, Mon, etc.)

    • command-commands to execute (commands can be commands such as Ls/proc >>/tmp/proc, or commands to execute scripts you write yourself. )

In any of these values, an asterisk (*) can be used to represent all valid values. For example, an asterisk in a month value means that the command is executed monthly after other constraints have been met.

The short line between integers (-) specifies an integer range. For example, 1-4 means integers 1, 2, 3, 4.

Specify a list with a series of values separated by commas (,). For example, 3, 4, 6, 8 indicate these four specified integers.

A forward slash (/) can be used to specify the interval frequency. Adding/<integer> after a range means that integers can be skipped within the range. For example, 0-59/2 can be used to define every two minutes in the Minutes field. The interval frequency value can also be used with asterisks. For example, the value of */3 can be used in the month field to indicate that the task runs every three months.

The line that starts with the pound sign (#) is a comment and will not be processed

LINUX/ETC/CRON.D function (turn from scheduled task crontab CRON.D)

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.