Scheduled start of Scheduled tasks (reproduced from the network)

Source: Internet
Author: User
Tags crontab example

Author: Zhu Maohai/Category: Faq/tag:crontab

Each operating system has its automatic Timer launcher function, Windows has its Task Scheduler, and Linux corresponds to the function of crontab.

Crontab Introduction

The crontab command is commonly used in Unix-and Unix-like operating systems to set 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.  The word derives from the Greek language Chronos (Χρ?νος), which was originally meant to be time. Typically, crontab stored instructions are activated by the daemon, Crond often run in the background, checking every minute for scheduled jobs to be executed. This type of work is generally called cron jobs.

Crontab usage

The format of the crontab is as follows:

F1 F2 F3 f4 f5 program

Where F1 is expressed in minutes, F2 represents hours, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. program indicates the path to execute.

    • When F1 is * indicates that every minute the program,f2 is executed, the program is executed every hour, and the rest of the analogy
    • When the F1 is a-B, it is executed from the time of the minute to the minute of the hour, and the F2 is a-B indicating that it is executed from the first and the other, and the other analogy
    • When F1 is */n, it is executed once every n minutes, F2 is */n for every n-hour interval, and the rest of the analogy
    • When F1 is a, B, C,... A, B, C,... Minutes to execute, F2 for a, B, C,... The time indicated that the first, B, c ... Hours to execute, and the rest of the analogy

Admin login ssh, enter command crontab-e edit crontab file, enter and save according to the above format.

crontab Example

The/bin/ls is performed at the first 0 minutes of every day per month:

    1. 0 * * * */BIN/LS

In December, the/usr/bin/backup is performed every 20 minutes in the morning from 6 to 12 hours per day:

    1. */20 6-12 */usr/bin/backup

Monday to Friday every 5:00 send a letter to [email protected]:

    1. 0 * * 1-5 mail-s "HI" [Email protected]omain.name </tmp/maildata

Every day of the month 0:20 midnight, 2:20, 4:20 .... Perform echo "haha"

    1. 0-23/2 * * * echo "haha"

Every two hours between 11 o'clock and 8 in the morning, 8 in the morning.

    1. 0 23-7/2,8 * * * Date

In HP Unix, every 20 minutes, it is represented as: 0,20,40 * * * * * instead of using */n mode, or syntax error occurs

Crontab usage is very easy to master, understand the use of crontab, the site and server maintenance to play a great help, such as scheduled backup, timing optimization server.

Scheduled start of Scheduled tasks (reproduced from the network)

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.