Brief analysis of Crontab command

Source: Internet
Author: User

The crontab command is used to set the instructions that are executed periodically. The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution.

Cron system scheduling process. You can use it to run a job during a daily non-peak load period, or at different times of the week or January. Cron is the main scheduling process for a system that can run jobs without human intervention. The crontab command allows the user to submit, edit, or delete the corresponding job. Each user can have a crontab file to hold the dispatch information. System administrators can disable or allow users to own their own crontab files via the Cron.deny and cron.allow two files.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/9A/wKioL1epn1ChBvHyAAAezF4J4SI958.png-wh_500x0-wm_3 -wmp_4-s_3295904961.png "title=" Qq20160809170906.png "alt=" Wkiol1epn1chbvhyaaaezf4j4si958.png-wh_50 "/>

The crontab file is typically located under/etc/, which stores the scheduler running on the system.

The first four rows are the environment variables that are used to configure the Crond task to run, the shell variable specifies which shell the system will use, this is bash, and the second line of the path variable specifies the path to the System execution command. The third line of the mailto variable specifies that Crond's task execution information will be emailed to the root user, and if the value of the mailto variable is null, the task execution information is not sent to the user, and the home variable in line fourth specifies the home directory to use when executing the command or script.

Each user generates an auto-generated crontab file, typically located in the/var/spool/cron directory

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/85/9A/wKiom1epn3mBfEp3AAALOZTTRaA192.png-wh_500x0-wm_3 -wmp_4-s_4256446072.png "title=" Qq20160809171358.png "alt=" Wkiom1epn3mbfep3aaalozttraa192.png-wh_50 "/>

/etc/cron.deny represents a user who cannot use the crontab command

/etc/cron.allow represents a user who can use crontab.

By default, the Cron.allow file does not exist. If two files exist at the same time, then/etc/cron.allow is preferred. If none of the two files exist, only the Superuser can schedule the job.

Command anatomy:

1. Create crontab Service and edit

crontab-e: time to execute script + script command executed + path stored by script


2. Check if the script was created successfully

Crontab-l


3. Start the service

/sbin/service Crond Start


4. Check if it is running

Ps-ax | grep cron


5. Related commands

Crontab-u: Set a user's Cron service, which is typically required by the root user when executing this command
Crontab-l: List details of a user's cron service
Crontab-r: Delete a cron service with no users

CRONTAB-E: Editing a user's cron service

6. Grammar

Hour of the week order

0-59 0-23 1-31 1-12 0-6 command

(Value range, 0 for Sunday One-like line for one task)

Meaning of several special symbols:

"*" represents a number in the range of values,
"/" stands for "every",
"-" represents a number to a number,
"," separate a few discrete numbers

such as: 7 8 * * ls specifies 7:30 minutes of 8th per month to execute the LS command


7. New Scheduling task

1), at the command line input: CRONTAB-E and then add the corresponding task, Wq save the disk to exit.

2), directly edit the/etc/crontab file, that is, vi/etc/crontab, add the corresponding task.


8. View Tasks

Crontab-l: Lists all the current scheduled tasks

Crontab-l-u JP: Lists all scheduling tasks for user JP


9, delete task scheduling work
Crontab-r




This article is from the "July boreas" blog, please be sure to keep this source http://luminous.blog.51cto.com/10797288/1836208

Brief analysis of Crontab command

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.