cron is a timed execution tool for Linux that runs jobs without human intervention. Since Cron is a built-in service for Linux, but it does not automatically get up, you can start and shut down the service in the following ways:
/sbin/service crond start //Start the service
/sbin/Service crond stop //close service
/sbin/service crond restart //restart service
/sbin/service crond reload //reload configuration
You can also This service is automatically started when the system is started:
At the end of the /etc /rc.d/rc.local script:
/sbin/service crond start
Now that the Cron service is already in the process, we can use this service. The Cron service provides the following interfaces for everyone to use:
1. Edit directly with the crontab command
The cron service provides the crontab command to set the cron service. The following are some parameters and descriptions of this command:
crontab -u //Set a user's cron service, generally the root user is executing this This parameter is required when the command is
crontab -l //list some use The details of the cron service
crontab -r //delete the cron service without a user
crontab -e //edit a user's cron service
For example, root Check your own cron settings: crontab -u root -l
For example, root wants to delete fred's cron settings: crontab -u fred -r
When editing the cron service, edit the content There are some formats and conventions, enter: crontab -u root -e
Enter the vi edit mode, the edited content must conform to the following format: */1 * * * * ls >> /tmp/Ls.tx t
crond resident command for task scheduling
crond is a command that linux uses to execute programs on a regular basis. This task scheduling command is initiated by default when the operating system is installed. The crond command periodically checks for work to be performed every minute, and if there is work to be performed, it will be automatically executed.
1. The task of linux task scheduling is mainly divided into the following two categories:
*The work performed by the system: the work to be performed periodically by the system, such as backing up system data, cleaning the cache
*Personal Execution: A job that a user does on a regular basis, such as checking the mail server for new messages every 10 minutes, which can be set by each user.
2.crontab command options:
-u specifies a user,
-l lists a user's task plan,
-r delete A user's task,
-eEdit a user's task
3.cron file syntax:
minute hour, month, and week week command
0-59 0-23 1-31 1-12 0-6 command (value range, 0 means that a general line corresponds to a task on Sunday)
4. Remember the meaning of several special symbols:
"*" represents a number in the range of values,
"/" stands for " every ",
"-" represents from some Number to a number,
"," separate several discrete numbers
First, the task scheduling setting file is written
can be edited with crontab -e command Edit the user's cron file under /var/spool/cron, or modify the /etc/crontab file directly
The specific format is as follows:
Minute Hour Day Month Dayofweek command
Minutes, hours, days, days, and weeks Order
Each field represents the following meaning:
Minute Performs the task every few minutes of the hour
Hour performs the task for the first few hours of the day
>
Day Perform the task on the first few days of the month
Month Perform the task in the first few months of each year
DayOfWeek Perform the task on the first few days of each week
Command Specifies the program to be executed
In these fields, except for the fields that must be specified each time, the other fields are optional fields, which can be determined as needed. For fields that are not specified, use “*” to fill their location.
Examples are as follows:
5 * * * * ls Specifies the ls command to be executed once every 5 minutes of the hour
30 5 * * * ls specifies 5:30 every day Execute the ls command
30 7 8 * * ls Specify 7:30 on the 8th of each month to execute the ls command
30 5 8 6 * ls Specify 5:30 on June 8th of each year Execute the ls command
30 6 * * 0 ls Specify to execute the ls command every 6:30 on Sunday [Note: 0 means Sunday, 1 means week 1, and so on, it can also be expressed in English, sun means On Sunday, mon said Monday and so on. ]
30 3 10,20 * * ls Execute the ls command at 3:30 on the 10th and 20th of each month [Note: “, & rdquo; used to connect multiple non-contiguous time slots]
25 8-11 * * * ls Execute the ls command at the 25th minute of 8-11 every day [Note: “-” used to connect consecutive time periods]
*/15 * * * * ls Execute the ls command every 15 minutes [ie 0 15 30 45 per hour 60 minutes to execute the ls command]
30 6 */10 * * ls Every 10 days, every 10 days : 30 Execute an ls command [that is, execute the ls command at 6:30 on the 1, 11, 21, and 31 of each month. ]
Execute all executables in the /etc/cron.daily directory as root at 7:50 every day
50 7 * * * root run-parts /etc/cron.daily [ ,null,null,3],Note: The run-parts parameter indicates that all executable files in the following directory are executed. ]
Second, the new scheduling task
There are two ways to add a new scheduling task:
1. At the command line, type: crontab -e and add the corresponding task. Wq saves and exits.
2, directly edit the /etc/crontab file, vi /etc/crontab, add the corresponding task.
Third, view the scheduling task
crontab -l //list all current scheduling tasks
crontab -l -u jp //list all scheduling of user jp Task
Fourth, delete the task scheduling work
crontab -r //delete all task scheduling work
Five, the task scheduling execution results of the steering
1: Execute the ls command at 5:30 every day and output the result to the /jp/test file
30 5 * * * ls >/jp/test 2>&1
Note: 2>&1 indicates the execution result and error message.
Edit /etc/crontab file configuration cron
The cron service not only reads all the files in /var/spool/cron every minute, but also needs to read /etc/crontab once, so we Configuring this file can also do something with the cron service. The configuration with crontab is for a certain user, and editing /etc/crontab is a task for the system. The file format of this file is:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO= Root //If there is an error, or there is data output, the data is sent to this account as an email
HOME=///The path the user runs, here is the root directory
# run-parts
01 * * * * root run-parts /etc/cron.hourly //execute scripts in /etc/cron.hourly every hour
02 4 * * * root run-parts /etc/cron.daily //Execute scripts in /etc/cron.daily every day
22 4 * * 0 root run-parts /etc/cron.weekly //execute /etc/cron every week. Scripts in weekly
42 4 1 * * root run-parts /etc/cron.monthly //execute the scripts in /etc/cron.monthly every month
Note to everyone" Run-parts" This parameter, if you remove this parameter, you can write a script name to run later, instead of the folder name.
For example: 1. At the command line, type: crontab -e Then add the corresponding task, wq save and exit.
2, directly edit the /etc/crontab file, ie vi /etc/crontab, add the corresponding task
11 2 21 10 * rm -rf /mnt/fb
Nginx has been widely used in production environments compared to Apaches high performance and high
Windows, Linux systems support interface themes, you can easily change your face, and it is not dif
First, download the magent download address: http://pan.baidu.com/s/1eRygtEUmkdir -p /usr/local/mag
Layer 2 Tunneling Protocol (L2TP) is an industry standard Internet tunneling protocol that uses UDP
Threaded process classic linux article
Linux operating system firewall configuration modification instruction set
How to reset MySQL ROOT password under Linux
Linux device driver development environment build
Git did not exit cleanly (exit code 128) solution
The principle and function of Redo log
Linux traffic monitoring script
How to view the hard disk model and hard disk serial number
Telecom User VPN Dial-in Service Settings
Win8.1 boot into the system does not have boot music reasons and solutions
160wifi mobile version for you to guard the network security
Win7 system under Baidu cloud network disk offline download resource prompt error 36000 solution
Win8 input method can not switch can not display the language bar
How to use QQ to transfer picture video files to iphone under Win10 system
Integrate the usual drivers for notebooks into the win7 system CD
Win10 game can not be full screen how to do? Win10 play game screen /can not full screen solution
How to add contacts to the Win8 network application
Using Linux routing and forwarding function to share the Internet