Specification and precautions for writing timed task process in Linux system

Source: Internet
Author: User
Tags crontab syntax

Timed task editing specification process:

Important points of knowledge:
切记用全路径编写定时脚本、定时任务大部分在 crontab 计划任务中都会年到未尾带 >/dev/null 2>&1,是什么意思呢?> 是重定向/dev/null 代表空设备文件1 表示stdout标准输出,系统默认值是1,所以 ">/dev/null" 等同于 "1>/dev/null"2 表示stderr标准错误& 表示等同于的意思,2>&1,表示2的输出重定向等同于1

The meaning of the sentence is that the standard output redirects to the empty device file, that is, does not output any information to the terminal, the standard error output redirection is equivalent to the standard output,
Standard error output is also redirected to an empty device file because the standard output was previously redirected to an empty device file

&>/dev/null 即不管输出是什么都从定向到/dev/nullcommand > file 2>file 与 command > file 2>&1 有什么区别呢?command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command > file 2>file 这样的写法,stdout和stderr都直接送到file中, file会被打开两次,这样stdout和stderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道。而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdout和stderr的内容。从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会用command > file 2>&1 这样的写法。
Timed task Syntax:
01  *     *    *      *     cmd分   时   日   月   周   任务

The meaning of the time period in the CRONTAB syntax format is the following table
Segment meaning value range (integer)
The first paragraph represents the minute 00–59 (00 can also be 0)
The second paragraph represents the hour 00–23
The third paragraph represents day, day 01–31
The fourth paragraph represents the month 01–12
The fifth segment represents the week, the week 0-7 (0 and 7 are all represented Sunday)
Hint: Time Memory formula (timeshare week). Value range record (normal date time range)

Timed task Edit location:/etc/crontab
Edit timed Task: CRONTAB-E
View current User timing tasks: crontab-l

Examples of timed tasks:

*/5 * * * * wget -q -O- | sh

Specification and precautions for writing timed task process in Linux system

Related Article

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.