Create a scheduled task using crontab in CentOS

Source: Internet
Author: User

Create a scheduled task using crontab in CentOS

In Linux, you can use crontab to create a scheduled task.

Common integrations

Crontab-e: edit a task

Crontab-l view all tasks [this user]

Crontab-r cancels all tasks [this user]

Task format

××××× + Command (specific task)

The first five parameters indicate the time, which is:

Parameter range

Minute 0-59

Hour 0-23

Date 1-31

Month 1-12

Week 0-6 (0 represents Sunday)

Special symbols

To accurately represent timing, special symbols are required to describe the specific task execution time. There are several symbols:

"/" Indicates the interval of each and every second.

"*" Indicates any time

"-" Indicates a period of time from one time point to another.

"," Indicates the discrete time.

Case

0 8 1 1 0 command executed at every year on January 1, January 1

*/30 * the command is executed every 30 minutes.

0 6-18 *** command: Execute command from to every day

At, and every day, the command is executed

0 6-18/3 ***/user/bin/PHP/var/www/html/save. php is executed every three hours from to every day using/user/bin/php/var/www/html/save. php

Note:

The commands set in crontab are relative paths, so the scripts executed in the command should be set to absolute paths as much as possible. On the other hand, if there is output in the script, it will be output to the current user directory. Therefore, if there is a path in the script, set it to an absolute path!

Crontab errors will be sent to the user by email. The directory in centos is/var/spool/mail/user. long-term accumulation may result in excessive space occupation in/var/and should be cleared in time. (DG in vi)

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.