The use of cron in Unix/linux

Source: Internet
Author: User

Cron is a command for timed tasks under UNIX or Linux, with the following general usage: 1. Start and close of service/sbin/service crond Start//Startup service/sbin/service Crond stop//Shut down service/sbin/service crond Restart//Restart service/sbin/service Crond Reload//Reload configurationYou can also make the service self-booting at boot time: at the end of the/etc/rc.d/rc.local script, add the following script: /sbin/service crond Start2. Edit Cron Servicecrontab-u//Set a cron service for a user, typically the root user needs this parameter when executing this command crontab-l//list details of a user cron servicecrontab-r//delete a cron service with no userscrontab-e//Edit a user's cron serviceuse crontab-u user-e to enter VI editing mode, the content of the edit must conform to the following format: * * * * * commandThe first part of this format is the setting of the time, the next part is the command to execute, of course, this command can also be a script. The functions of the five * are as follows: minutes (0-59)
Hours (0-23)
Date (1-31)
Month (1-12)
Week (0-6)//0 representative Sunday after editing a user's cron settings, Cron automatically generates a file with the same name as the user under/var/spool/cron, and the cron information for this user is recorded in this file, which cannot be edited directly and can only be edited with CRONTAB-E. After Cron starts, read the file once every one of the clocks, and check to see if you want to execute the command inside. Therefore, the Cron service does not need to be restarted after this file has been modified. 3. Timing Method DescriptionIn addition to the numbers, there are a few special symbols ("*", "/" and "-", ",") can be used to edit the start time, * represents all the values within the range of the number, "/" for each meaning, "*/5" for every 5 units, "-" represents from a number to a number, "," Separate several discrete numbers. Here are a few examples to illustrate the problem:every morning 6:0 6 * * Commandevery two hours: 0 */2 * * * command11 o'clock to 8 a.m., every two hours, eight a.m.: 0 23-7/2,8 * * * command.number 4th per month and Monday to Sunday, three a.m. 11:0 4 * 1-3 commandJanuary 1 Morning 4:0 4 1 1 * Command 4, the configuration file/etc/crontab editThe cron Service not only reads the files in/var/spool/cron once per minute, but also reads the/etc/crontab, so we can configure this file to do something with the cron service. The crontab configuration is for a user, while the edit/etc/crontab is a task for the system. The file format for this file is:Shell=/bin/bashPath=/sbin:/bin:/usr/sbin:/usr/binMailto=root//If an error occurs, or if there is data output, the data is sent to this account as an emailhome=///user-run path, here is the root directory# Run-parts* * * * * root run-parts/etc/cron.hourly//hourly execution of scripts within/etc/cron.hourly4 * * * Root run-parts/etc/cron.daily//daily execution of scripts within/etc/cron.daily4 * * 0 root run-parts/etc/cron.weekly//weekly execution of scripts within/etc/cron.weekly4 1 * * Root run-parts/etc/cron.monthly//monthly to execute scripts within/etc/cron.monthlyattention to the "run-parts" This parameter, if you remove this parameter, you can later write to run a script name, not the folder name. 5. Permission SettingsBy default, all users have access to the Cron tool, and you can generate/etc/cron.allow and/etc/cron.deny files for access control of cron. ①, when none of these two files exist, each user has access to the Cron tool. ②, by default, there should be Cron.deny (empty text), Cron.allow need to create their own. ③, the/etc/cron.allow file exists, only the users allowed in the Cron.allow file can access the Cron tool, and if there is a/etc/cron.deny file, the contents of the Cron.deny file are ignored.

The use of cron in Unix/linux

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.