Crontab Scheduled Task configuration record, crontab task _php Tutorial

Source: Internet
Author: User

Crontab Scheduled Task configuration record, crontab task


First, preface

Today, simply record the configuration of the crontab

Ii. Catalogue of Crontab

/etc/crontab file    This is the scheduled task for the system to run/var/spool/cron directory    user-defined crontab tasks are placed in this directory ls–lrt/etc/cron*   /etc/cron.deny Represents a user who     cannot use the crontab command   /etc/cron.allow     represents a user who can use the crontab command   by default, Cron.allow does not exist, if all exists, Cron.allow first

Third, crontab command syntax

Specific crontab--help or man crontab|morecrontab–l   //View the current user's scheduled Tasks crontab–e  //Edit the current user's scheduled Tasks  Crontab–r// Delete the current user's scheduled tasks

Iv. crontab Task Format

* * * *  /home/xxx/crontab/test.sh >/dev/null  2>&1 & Top 6 columns for the time being C1 (  1-59) C2  ( 1-23,0 means midnight) C3 Day  (1-31) C4 month  (1-12) C5 Week  (0-6,0 for Sunday, 1 for Monday, and so on) C6 the first 5 columns of the command to run indicate how often the command executes, the minimum frequency is once per minute, Where the value of CN can be expressed in four forms: *  ,  */n  , t1-t2, A,b,c  when the C1 is *, the command is executed every minute when C1 is */n, the command is executed every n minutes when C1 is T1-t2, it represents from T1 Clock to T2 minutes time to execute the command when C1 is A,b,c, the a,b,c minute is executed to execute the command example call: * * *  /home/xxx/crontab/test.sh >/dev/null 2>& Amp;1 represents a daily 12:12 execution script */2 * * * *  /home/xxx/crontab/test.sh >/dev/null 2>&1 means every 2 minutes Execute a SCRIPT 0 * * 1-5  /home/xxx/crontab/test.sh >/dev/null 2>&1 The script is executed at 23 points every Monday to Friday 0 * * 0  mail-s "xxx "Xxx@mail.com </tmp/maildata means 19 points per Sunday to send mail to xxx@mail.com

V. Instructions on the Order

Explanation of/dev/null 2>&1 in the command 0 means that keyboard input 1 means that standard output 2 means Error Output 1. Create the test.sh, as follows #! /bin/bashecho "Time is" ' date ' 2. Adding timed Tasks * * * * *    /home/xxx/crontab/test.sh >/home/xxx/crontab/test.log &    The default is 1, and the following method is consistent * * * * *   /home/xxx/crontab/test.sh 1>/home/xxx/crontab/test.log &* * * * *   /home/xxx/crontab /test.sh >/home/xxx/crontab/test.log  2>&1 &3. Description 1 represents, standard output, so the above command will output the script output to the log file specified later, Instead of printing to the screen; 2 means, error output, &1 represents the description of the file, this indicates that the error message executed by the script is redirected to 1 (standard output) and 1 has been redirected to the specified log file, so the information will be output to the log file can not be written 2>1, missing & will be considered an error message output to the name 1 file

VI. matters of caution

1.shell environment variables to set the necessary environment variables  crontab default does not include the environment for the current user of the system, so you need to add the necessary environment variables 2. Use the full path approach as much as possible and avoid using relative paths 3. Avoid repeated execution of the script  if (EXEC ("PS -ef |grep ' php ' |grep ' updatescript ' |grep-v ' grep ' |wc-l ') > 2) {die    ();    }  Grep-v ' grep '    indicates the result to filter out grep's line  wc-l             represents the number of rows that meet the criteria  so you can tell if a script named Updatescript has been executed in the PHP process.

Vii. references

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

http://www.bkjia.com/PHPjc/1048757.html www.bkjia.com true http://www.bkjia.com/PHPjc/1048757.html techarticle crontab Scheduled Task configuration record, crontab task one, preface today simple record crontab configuration two, crontab directory/etc/crontab file This is the system to run the scheduling task/var/sp ...

  • 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.