The crontab command is common in UNIX and Linux operating systems and is used to set periodically executed instructions. This command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution. Typically, crontab stored instructions are activated by the daemon. Crond often runs in the background and checks every minute to see if there are scheduled jobs to perform. This type of assignment is commonly referred to as cron jobs.
First, installation
Yum-y Install Vixie-cron
Yum-y Install Crontabs
Second, the configuration
Cron is a built-in service for Linux, but it does not automatically get up, you can start and close the service in the following ways:
Service Crond start/starting Services
Service Crond stop//off services
Service Crond restart//Restart services
Service Crond Reload//Reload Configuration
Service Crond Status//view Crontab service state
To add the boot auto start to the CentOS system: Chkconfig--level 345 Crond on
Third, add a task
Method 1:
Use the command crontab-e and then edit the timed script directly.
After this implementation, the user-defined, will be written to the/var/spool/cron directory, to generate a consistent user name file, the file content is our edited timed script.
Edit directly with crontab command
The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:
Crontab-u//Set a user's Cron service, which is required by the general root user when executing this command
CRONTAB-L//list details of a user's cron service
Crontab-r//Delete a user's cron service
CRONTAB-E//Edit a user's cron service, such as root view your cron settings: Crontab-u root-l
Again for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
Basic format:
Time-sharing and Lunar Week command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 for 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
The 5th list of the week 0~6 (0 for Sunday)
Method 2:
Use the command Vi/etc/crontab to edit the timed script.
It includes the following lines:
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/
# Run-parts
* * * * Root run-parts/etc/cron.hourly
4 * * * Root run-parts/etc/cron.daily
4 * * 0 root run-parts/etc/cron.weekly
4 1 * * Root run-parts/etc/cron.monthly
The first four lines are variables used to configure the Cron task's running environment.
The value of the shell variable tells the system which shell environment to use (in this case, the bash shell);
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.
If you do not add the Run-parts parameter, write the task file directly, not the folder.
(System level) do system-level configuration we will directly configure/etc/crontab
(User-level) is generally recommended to use CRONTAB-E, so the system will also help check our configured script syntax.
crontab Example
Execute */5 * * * * every five minutes
0 per hour * * * * * *
Daily Execution 0 0 * * *
Perform 0 0 * * 0 per week
0 0 1 * * * per month
Annual Implementation 0 0 1 1 *
Set cron Permissions
/etc/cron.allow
/etc/cron.deny
The system first determines whether there is a cron.allow this file, if this file, the system will determine if the user is in the Cron.allow list, if the list, you can use the cron mechanism. If the user is not in the Cron.allow list, the cron mechanism cannot be used.
If the system does not cron.allow this file, the system will judge whether there is cron.deny this file, if there is cron.deny this file, it will determine if the user is in the Cron.deny list, if the user in the Cron.deny list, will You cannot use a cron mechanism. You can use the cron mechanism if the user is not in the Cron.deny list.
If none of the two files in the system is available, you can use the cron mechanism