Note: This note is summarized in the horse Brother's lecture notes
2015-09-16
linux-Scheduled Tasks
Defined:
The so-called planning task is that the server every day has access to the pressure of the time and the pressure is small, and according to our daily maintenance of the average server at night pressure is small, and we do large operations must avoid the server business peak and the server pressure is too high, So we will choose to do the operation at night, and these operations are only to execute a command, we have to wait until the next day to execute the command, then we use the function of the planning task, scheduled task is a one-time or periodic execution of the task, then Linux for us to prepare two kinds of planning tasks, One is to only perform an at schedule task and a cron scheduled task that can be executed periodically.
At Scheduled Tasks
Which is a one-time scheduled task
Usage:
At option time
Time is divided into:
Absolute time the so-called absolute time is in a few minutes or a few months of the number of days when the number of minutes format: hh:mm (15:23) yy-mm-dd
Relative time expression is Now+minute (min) hour (hours) day (days) week (week)
Blur Time Midnight Midnight Noon Noon Wait
Example:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/49/wKiom1X5Hx7R5nf4AAB2ocPTRnY338.jpg "title=" 5.png " alt= "Wkiom1x5hx7r5nf4aab2ocptrny338.jpg"/>
Options:
-M sends the message to the user after the scheduled task execution is finished
-L View User plan
-D Delete User plan
-C View the details of the at program
-F reads the job to be executed from the specified file
Example:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/47/wKiom1X5FZOiuLnwAAEStSDcb7A731.jpg "title=" 2.png " alt= "Wkiom1x5fzoiulnwaaestsdcb7a731.jpg"/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/45/wKioL1X5GLOTiKkqAAFB0gMkiH8814.jpg "title=" 3.png " alt= "Wkiol1x5glotikkqaafb0gmkih8814.jpg"/>
-F
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/49/wKiom1X5H73gFFx3AAB_yCWMujM158.jpg "title=" 6.png " alt= "Wkiom1x5h73gffx3aab_ycwmujm158.jpg"/>
We indicated in the first diagram that we did not start the ATD service, so we need to make sure that the ATD server is turned on when using a one-time scheduling task, otherwise the scheduled task will not be executed, we use service ATD start to start, such as:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/48/wKiom1X5FyLBwlTgAAB5opdUO9E757.jpg "title=" 4.png " alt= "Wkiom1x5fylbwltgaab5opduo9e757.jpg"/>
We're talking about a one-time scheduled task, but we sometimes have a task that needs to be run over and over again, so we're going to use a recurring mission plan, which we call "Cron."
Crontab Recurring Scheduled Tasks
Note:
Cron and at are all required to start the service, and the cron service is Crond, so we want to make sure that Crond is turned on when we use a recurring scheduled task, and that if the scheduled task does not start, we use service Crond start to open it, Then use Chkconfig Crond on to add a boot start
Example:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/49/wKiom1X5IrzDed2qAAHj6I_0RU0145.jpg "title=" 7.png " alt= "Wkiom1x5irzded2qaahj6i_0ru0145.jpg"/>
There are two types of recurring tasks:
1, System cron task; There is no default running user identity, so you need to specify the additional runner
Its running tasks in/etc/crontab generally use vim to edit, generally do not recommend to operate
2, User cron task, submitted by a user, the default is to run as the submitter, so there is no need to specify the additional runner
Its running task is under/var/spool/cron/username
The function and usage of the crontab command
Role: maintain periodic scheduled tasks for users
Usage: crontab [options]
-u Specifies the user who scheduled the task, default to the current user, note: Only root can specify another user.
-L View Scheduled Tasks
-R Delete Scheduled Tasks
-E Editing Scheduled Tasks
-I require the user to confirm the deletion when deleting a task using-r
Crontab Scheduled task format meaning such as: using the 24-hour system, the minute range 0~59, the hour range 00~23, the date range 1~31, the month range is 1~12, the week range is 0~7 (where 0 and 7 can be expressed as Sunday);
The division of the time period:
-Represents a continuous time example: 3-7 if the minute represents 3-7 minutes on this time period to execute
, indicating a discontinuous time example: 3,6,9 in the 3rd minute of every hour, 6th minute, 9th minute.
/# represents the frequency of each time in the effective range of the example: 1-30/4 means that 1-30 minutes per hour every 4 minutes of */4 is executed every 4 minutes
* Indicates all time
/indicates the time interval
Example: 5 */3 * * */bin/echo "Hello" means the following command is executed every 3 hours in the 5th minute
* */3 * * * */bin/echo "Hello" This means that every 3 hours, every minute, the following command is executed.
So we want to express every word of a time, we must specify a time in a unit smaller than it.
Example: 5 7 * * 1-5 /bin/echo "Hello" means Monday to Friday daily 7:5 run Once
The definition of the pattern is, for example, a system definition:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/4A/wKiom1X5LJPyfvJ3AAG1ZClywDM280.jpg "title=" 8.png " alt= "Wkiom1x5ljpyfvj3aag1zclywdm280.jpg"/>
This article is from the "It-style" blog, make sure to keep this source http://huichengu.blog.51cto.com/2495968/1695491
linux-Scheduled Tasks