Crontab error analysis and reason for not executing

Source: Internet
Author: User
CronCronisatime-basedjobschedulerinUnix-likecomputeroperatingsystems.Thenamecroncomesfromtheworldchronograph (atime-piece). Cronenablesuserstoschedulejo...
CronCron is a time-based job scheduler in Unix-like computer operating systems. the name cron comes from the world chronograph (a time-piece ). cron enables users to schedule jobs (commands or shell scripts) to run automatically at a certain time or date. it is commonly used to automatic system maintenance or administration, though its general purpose nature means that it can be used for other purposes, such As connecting to the Internet and downloading email .. ------ 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
In fact, I think the most common problem with Crontab is that the environment variable is incorrect. I often see people in the forum asking: why does my Crontab fail to be created? When creating a Cron JOB, many people like to run it in the command line, because the environment variables are automatically brought in with Shell, in Crontab, the JOB cannot be executed because the correct environment variable cannot be found. This small problem is like having a hard time, and I will remember it after a lesson. A required skill. after each JOB is executed, the system automatically sends an email to the current system user. It has been a lot of days and may even crash the entire system. Therefore, it is necessary to perform redirection after each JOB command:>/dev/null 2> & 1. The premise is that the commands in the Job need to be properly output, such as appending to a specific log file. 1. directly use the crontab command to edit the cron service and provide the crontab command to set the cron service. The following are some parameters and instructions for this command: crontab-u // Set the cron service of a user, generally, when executing this command, the root user needs this parameter crontab-l // to list the details of a user's cron service. crontab-r // delete the cron service crontab-e of no user. // edit the cron service of a user, for example, view the cron settings of the root user: crontab-u root-l again, for example, root wants to delete the cron setting of fred: crontab-u fred-r when editing the cron service, the edited content has some formats and conventions. input: crontab-u root-e enters the vi editing mode. the edited content must conform to the following format: */1 ***** ls>/tmp/ls.txt the first part of the format sets the time, and the other part is the command to be executed, as shown in If you want to execute too many commands, you can write these commands into a script, and then directly call this script here. remember to write the complete path of the command during the call. We have a certain agreement on the time setting. the first five * numbers represent five numbers. the value range and meaning of the numbers are as follows: minute (0-59) is small? R (0-23) Date (1-31) month (1-12) Week (0-6) // 0 indicates Sunday. in addition to numbers, there are also several special symbols: "*", "/", "-", and ",". * indicates the numbers in all values, "/" indicates the meaning of each. "*/5" indicates every five units. "-" indicates that a number is transferred to a number. "," separate several discrete numbers. The following example illustrates the problem: at every morning, *** echo "Good morning. ">/tmp/test.txt // pay attention to pure echo, and no output is visible from the screen, because cron has emailed any output to the root mailbox. 0 */2 *** echo "Have a break now. ">/tmp/test.txt every two hours from PM to AM, 8 * ** echo "Have a good dream :)">/tmp/test.txt: AM, AM, Am- 3 command line, January 1, January 1 4 1 1 * after each command line editing a user's cron settings, cron automatically generates a file with the same name as/var/spool/cron. The cron information of this user is recorded in this file and cannot be edited directly, you can only use crontab-e for editing. The cron reads the file every minute after it is started, and checks whether to execute the commands in it. Therefore, you do not need to restart the cron service after the file is modified. 2. edit the/etc/crontab file and configure the croncron service to read not only all files in/var/spool/cron once per minute, but also/etc/crontab once, therefore, we can use the cron service to configure this file. Crontab configuration is intended for a user, and editing/etc/crontab is a system task. The file format of this file is: SHELL =/bin/bashPATH =/sbin:/bin:/usr/sbin:/usr/binMAILTO = root // if an error occurs, or there is data output, the data is sent to the account HOME as a mail = // User running path, here is the root directory # run-parts01 *** root run-parts/etc/cron. hourly // Run/etc/cron hourly. hourly script 02 4 *** root run-parts/etc/cron. daily // Run/etc/cron every day. daily script 22 4 ** 0 root run-parts/etc/cron. weekly // Run/etc/cron every week. weekly script 42 4 1 ** root run-parts/etc/cron. monthly // Run/etc/cro every month Note the "run-parts" parameter for the script in n. monthly. If this parameter is removed, you can write a script name to be run later, instead of the folder name. In addition, crontab adds log 0 6 ***** $ HOME/for_crontab/createTomorrowTables> $ HOME/for_crontab/mylog. log 2> & 1 reference: http://en.wikipedia.org/wiki/Crontab
Author ZHB_McCoy

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.