CentOS command-crontab: Job Scheduling

Source: Internet
Author: User

CentOS command-crontab: Job Scheduling

Cron is a Linux scheduled execution tool that can run jobs without human intervention. The cron daemon reads the crontab file and executes the task at the specified time according to the configuration.
The contab command is used to add, delete, and display a cron task table.

(Ubuntu environment) You can use the service command to start and stop the cron service:
Service cron status # view the cron service status
Service cron start # start the cron service
Service cron stop # stop the cron service
Service cron restart # restart the cron service
Service cron reload # reload the cron service configuration

Crontab command Command Format

Crontab [-u user] file
Crontab [-u user] [-l |-r |-e] [-I] [-s]

Command Parameters

-U
Specified user

-L
Displays the contents of the current crontab file.

-R
Delete the contents of the current crontab file.

-E
Edit the content of the current crontab file. If the file does not exist, create a new file.

-I
A prompt is displayed when you delete the crontab file.

Crontab file

Format: minute hour day_of_month month day_of_week command

Field description

Field descriptionMinute, value range: (0-59) hour, value range: (0-23) day_of_month date, value range: (0-31) month, the value range is (1-12). You can also use jan, feb, mar, apr... day_of_week week. The value range is (0-6). The value is 0 or 7 on Sunday, or sun, mon, tue, wed, thu, fri, sat indicates the command to be executed by the command

Special symbol meaning

Special symbol description* For all possible values, specify the value list, for example, 1, 3, 5, 7, 9-specify the Integer Range, for example, 1-5/Specify the Interval Frequency.

Cron expression example

Example*/15 * execute the task 0 */2 * every 2 hours every 15 minutes, execute the task 0 3 * at every day on the hour. Execute the task 0 0, 5, 15, 25 * on the 5 th and 15 th of each month, task execution at AM on the 25 th is between and every Monday, execute the task on the hour or on the hourInstance

A) add a cron task

huey@huey-K42JE:~/huey/linux/cmdline$ echo "*/3 * * * * date >> ~/huey/linux/cmdline/cron.out" > mycronhuey@huey-K42JE:~/huey/linux/cmdline$ crontab mycron

B) delete a cron task

huey@huey-K42JE:~/huey/linux/cmdline$ crontab -r

C) display cron tasks

huey@huey-K42JE:~/huey/linux/cmdline$ crontab -l*/3 * * * * date >> ~/huey/linux/cmdline/cron.out

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.