Linux crontab configuration files and commands __linux

Source: Internet
Author: User

1, cron service every minute not only to read all the files within the/var/spool/cron, but also need to read a/etc/crontab, so we configure /etc/crontab The file can also do something with the cron service (the crontab configuration is for a user, and the edit/etc/crontab is a task for the system).


2,/etc/crontab file:


The first four lines are variables used to configure the Cron task's environment to run:

The value of the shell variable tells the system which shell environment to use.

The path variable defines the paths used to execute the command.

The output of the cron task is mailed to the user name defined by the MAILTO variable. If the MAILTO variable is defined as a blank string (mailto= ""), the e-mail message is not sent.

The home variable can be used to set the master directory to use when executing commands or scripts.

* * * * * root run-parts/etc/cron.hourly//hourly execution of scripts within/etc/cron.hourly
4 * * * Root run-parts/etc/cron.daily//daily execution of/etc/cron.daily scripts
4 * * 0 root run-parts/etc/cron.weekly//per week execute/etc/cron.weekly script
4 1 * * Root run-parts/etc/cron.monthly//monthly to execute/etc/cron.monthly script

Use the Run-parts script to execute scripts in the/etc/cron.hourly,/etc/cron.daily,/etc/cron.weekly, and/etc/cron.monthly directories, which are accordingly hourly, daily, weekly, or monthly execution. The files in these directories should be shell scripts.


3, each row in the file represents a task, and its format is:

Minute hour day Month DayOfWeek command

minute-minutes, any integers from 0 to 59

hour-hours, any integer from 0 to 23

day-date, 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 the English abbreviation for the month used, such as the long, Feb, etc.)

Dayofweek-week, any integer from 0 to 7, where 0 or 7 represent Sunday (or use the English shorthand for the week, such as sun, Mon, etc.)

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


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

A dash (-) between integers specifies a range of integers. For example,1-4 means integers 1, 2, 3, and 4.

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

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

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


4. If a cron task needs to be performed according to schedule instead of hourly, daily, weekly, or monthly execution, it can be added to the/ETC/CRON.D directory.


5, control the use of cron

/etc/cron.allow and/etc/cron.deny files are used to restrict the use of cron.

Both of these use control files are formatted as one user per line. No spaces are allowed for two files. 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 the rules in the control file.

If the Cron.allow file exists, only the users listed therein 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.


6. The cron daemon checks for changes in/etc/crontab files, etc/cron.d/directories, and/var/spool/cron directories every minute. If a change is found, they are loaded into memory. This way, when a crontab file changes, you do not have to restart the daemon.





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.