Crontab scheduled task configuration record

Source: Internet
Author: User
: This article describes the configuration record of crontab scheduled tasks. For more information about PHP tutorials, see. I. Preface

Record the crontab configuration today

II. crontab Directory

The/etc/crontab file is the scheduling task run by the system. the custom crontab task in the/var/spool/cron directory is stored in the ls-lrt/etc/cron */etc/cron directory.. deny indicates that the user/etc/cron cannot use the crontab command. allow indicates that the crontab command can be used by default. allow does not exist. if both exist, cron. allow priority

III. crontab command syntax

You can choose crontab -- help or man crontab | morecrontab-l // view the current user's scheduled task crontab-e // edit the current user's scheduled task crontab-r // delete the current user's scheduled task

IV. crontab task format

59 23 ***/home/xxx/crontab/test. sh>/dev/null 2> & 1 & When C1-C6 is used to represent C1 score (1-59) C2 for the first 6 columns (1-23,0 indicates midnight) c3 (1-31) C April (1-12) C5 week (0-6, 0 indicates Sunday, 1 indicates Monday, and so on) the first five columns of the command to run C6 indicate the frequency of command execution, the minimum frequency is once per minute, where the value of Cn can be expressed in four forms: *, */n, T1-T2,, b, c when C1 is *, it means to execute command every minute when C1 is */n, it means to execute command every n minutes when C1 is T1-T2, the command is executed from T1 minutes to T2 minutes. When C1 is a, B, c, it indicates that the command is executed in the, B, and c minutes. example calls: 12 12 ***/home/xxx/crontab/test. sh>/dev/null 2> & 1 indicates that the script is executed at every day */2 *****/home/xxx/crontab/test. sh>/dev/null 2> & 1 indicates that the script 0 23 ** 1-5/home/xxx/crontab/test is executed every 2 minutes. sh>/dev/null 2> & 1 indicates that the script is executed every Monday to Friday 0 19 ** 0 mail-s "xxx" xxx@mail.com </tmp/maildata indicates that every Sunday send email to xxx@mail.com

V. Instructions on commands

The explanation of/dev/null 2> & 1 in the command 0 indicates that the keyboard input 1 indicates the standard output 2 indicates the error output 1. create test. sh. the content is as follows #! /Bin/bashecho "time is" 'date' 2. add a scheduled task *****/home/xxx/crontab/test. sh>/home/xxx/crontab/test. log & the default value is 1, which is consistent with the following method: *****/home/xxx/crontab/test. sh 1>/home/xxx/crontab/test. log & *****/home/xxx/crontab/test. sh>/home/xxx/crontab/test. log 2> & 1 & 3. note 1 indicates standard output. Therefore, the above Command will output the output result of the script to the specified log file later, instead of printing it to the screen. 2 indicates error output, & 1 indicates the description of the file. here, it indicates that the error message of script execution is redirected to 1 (standard output), and 1 has been redirected to the specified log file, therefore, all information is output to the log file and cannot be written as 2> 1. if & is missing, it is considered as an error message and output to the file named 1.

VI. Precautions

1. in shell, you need to set the required environment variable crontab. by default, the environment variable does not contain the current user's environment. Therefore, you need to add the required environment variable 2. try to use the full path method to avoid using the relative path 3. avoid repeated execution of scripts if (exec ("ps-ef | grep 'php' | grep 'updatescript' | grep-v 'grep' | wc-l")> 2) {die ();} grep-v 'grep' indicates that the result has been filtered out. the wc-l line of grep indicates that the number of rows meeting the condition is counted. in this way, the php process can be determined, whether the script named updateScript has been executed

VII. References

http://www.cnblogs.com/kerrycode/p/3238346.htmlhttp://www.cnblogs.com/hazir/p/sudo_command.html

The preceding section describes the configuration record of crontab scheduled tasks, including related content, and hopes to help anyone who is interested in PHP tutorials.

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.