[note] Scheduled tasks in Linux crontab

Source: Internet
Author: User

Can't refuse to progress

Cron comes from the Greek word chronos (meaning "time"), which is the next program (scheduled Task) of the Linux system that automatically executes the specified task.

Command options for 1--crontab #crontab-U <-l,-R,-e>-u Specifies a user-l list A user's task schedule-R to delete a user's task-e edit a user's task

Command syntax for 2--crontab

Use the Crontab–e command to start editing, or Vim/var/spool/cron

Format Description:

# Example of Job definition:
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * command to be executed

Minute Hour Day Month Week command
Minute hour day month week order
0-59 0-23 1-31 1-12 0-6 command

Minute the first few minutes of every hour to perform the task
Hour the first few hours of the day to perform this task
Day of the month to perform the task
Month months of the year to perform this task
DayOfWeek the day of the week, 0 indicates Sunday
command specifies the program, script, or command to execute

3--the meaning of several special symbols

"*" represents a number in the range of values,
"/" stands for "every",
"-" represents a number to a number,
"," separate a few discrete numbers

4--Points of attention

By default, if Cron sends a message to the user's local mailbox after each instruction, a large number of messages will be generated for a long time. So how do you stop it? It is possible to implement the following method
REDIRECT information for executing commands to
Cron_command >/dev/null 2>&1
REDIRECT information for executing commands to
Cron_command &>/dev/null

Do not forget to assign the Execute script file to the executable

. Assign the Execute script permission to the executable
Common examples of chmod +x filename 5--

0 6 * * * #每天早上6点
0 */2 * * * #每两个小时
0 23-6/2,8 * * * #晚上23点到早上6点之间每两个小时, eight a.m.
0 4 * 1-3 #每个月的4号和每个星期的星期一到星期三的早上11点
* * * #每晚的21:30
4 1,10,22 * * #每月1, 10, 22nd 4:45
1 * * 6,0 #每周六, Sunday 1:10
0,30 18-23 * * * #每天18:00 to 23:00 every 30 minutes
0 * * 6 #每星期六的23:00
* */1 * * * #每一小时
* 23-7/1 * * * #晚上11点到早上7点之间, every hour
0 4 * mon-wed #每月的4号与每周一到周三的11点
0 4 1 Jan * #一月一号的4点

[note] Scheduled tasks in Linux crontab

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.