CRONT foundation

xiaoxiao2021-03-06  20

Title: cron service configuration Explained Publisher: cold Date: April 2, 2004 are reading: 8470cron Service Configuration Explained Author: Fred Huang Source: www.xiaoxiang.net just made a backup module, and later Master Tip It is best to add an automatic backup function, so it is studying CRON. Cron is Linux's built-in service, but it does not automatically, you can start with the following method, close this service:

Quote: / SBIN / Service Crond Start // Startup Service / SBIN / Service Crond Stop // Close Service / SBIN / Service CROND RESTART // Restart Service / SBIN / Service CROND RELOAD / / Re-Load Configuration You can also use this service Automatically start when the system is started:

Quote: At the end of the script of /etc/rc.d/rc.local, add: / sbin / service crred Start Now cron This service is already in the process, we can use this service, the CRON service provides the following The interface is for you: 1. Use the crontab command to edit the cron service to provide a cron service, the following is some of the parameters and descriptions of this command:

Quote: crontab-u // Set a user's cron service, the general root user needs this parameter when executing this command, the parameter crontab -l // lists the details of a user cron service crontab -r // delete A user's cron service crontab-E // edits a user's CRON service, such as root, view your own CRON settings:

Quote: crontab -u root -l, for example, root wants to delete the Fred CRON setting:

Quote: crontab -u fred -r When editing the cron service, the edited content has some formats and conventions, and enter:

Quote: crontab -u root -e enters the VI edit mode, editing the content must meet the following format:

Quote: * / 1 * * * * LS >> /TMP/LS.txt This format The previous part is the set of time, the back part is the command to be executed, if you want to execute too much, you can put these commands Write to a script, then call this script directly, remember to write the full path to the command when calling. Time setting We have some agreement, the previous five * represent five numbers, the number of values ​​and meanings of the numbers are as follows:

Quote: Minute (0-59) Hours (0-23) Date (1-31) Month (1-12) Week (0-6) // 0 Represents Sunday in addition to the number there are several special symbols "* "," / "And" - ",", "represent the number of all values," / "represents every meaning," * / 5 "means every 5 units," - "representatives from a certain Number to a number, "," separate a few discrete numbers. The following example shows the problem:

Quote: 6pm 06 * * * echo "Good morning." >> /tmp/test.txt // Note Simple Echo, from the screen you can't see any output, because Cron puts any output email to root The mailbox. Every two hours 0 * / 2 * * * echo "Have a break now." /Tmp/test.txt 11:00 am to 8:00 in the morning, 8:23-7 / 2 , 8 * * * echo "Have a good dream :)" >> /TMP/test.txt Every month of the 4th and each week's worship, a worship 3 in the morning 11:00 11:4 * 1-3 Command LINE January 1st 0 4 0 4 1 1 * Commist Line After each editing a user's cron settings, CRON automatically generates a file as the same name with this user in / var / spool / cron, this user's CRON information Record in this file, this file is not directly edited, only CRONTAB -E can be edited. After CRON starts, read this file every time, check whether you want to perform the commands. So this file does not need to restart the CRON service after modification. 2. Edit / etc / crontab file Configuring Croncron Services not only read all files in / var / spool / cron per minute, but also need to read / etc / crontab, so we can configure this file and use CRON service to do something . The use of crontab is for a user, while editing / etc / crontab is a task for the system. The file format of this file is: reference: shell = / bin / bashpath = / sbin: / bin: / usr / sbin: / usr / binmailto = root // If there is an error, or data output, the data is sent as a message. Account home = / # run-parts01 * * * * root run-parts /etc/cron.Hourly // Each hour is executed in /etc/cron.Hourly script 02 4 * * Root Run-Parts / ETC /cron.daily / / Direction of scripts in /etc/cron.daily per day 22 4 * * 0 root run-parts /etc/cron.warekly / / per week to perform scripts in /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly // Each month to perform a script user running in /etc/cron.monthly, you pay attention to "run-part" parameters, if removed If this parameter, you can write a certain script name to run, not the folder name. This article has been modified by Fred from 2003-12-2 23:15:51.

转载请注明原文地址:https://www.9cbs.com/read-42749.html

New Post(0)