Scheduled automatic task crontab command usage

Source: Internet
Author: User
Tags crontab example
Crontab introduction crontab commands are common in Unix and Unix-like operating systems and are used to set periodically executed commands. This command reads commands from the standard input device and stores them in the crontab file for later reading and execution. The word is derived from the Greek chronos (QP? ν ο ?), The original intention is time. Generally, the commands stored in crontab are activated by the Daemon, and crond is often run in the background. check whether a scheduled job needs to be executed every minute. This type of job is generally called cro crontab introduction

Crontab commands are common in Unix and Unix-like operating systems and are used to set periodically executed commands. This command reads commands from the standard input device and stores them in the crontab file for later reading and execution. The word is derived from the Greek chronos (QP? ν ο ?), The original intention is time. Generally, the commands stored in crontab are activated by the Daemon, and crond is often run in the background. check whether a scheduled job needs to be executed every minute. This type of job is generally called cron jobs.

Crontab usage

The crontab format is shown below:

F1 f2 f3 f4 f5 program

F1 indicates the minute, f2 indicates the hour, f3 indicates the day of the month, f4 indicates the month, and f5 indicates the day of the week. Program indicates the path of the program to be executed.

  • When f1 is *, the program is executed every minute, when f2 is *, the program is executed every hour, and so on.

  • When f1 is a-B, it indicates that execution is performed from the minute a to the minute B. When f2 is a-B, it indicates that execution is performed from the hour a to the hour B, other analogy

  • When f1 is */n, the execution is performed every n minutes. if f2 is */n, the execution is performed every n hours.

  • When f1 is a, B, c ,... A, B, c ,... Execute in minutes. f2 is a, B, c ,... A, B, c... Execute in hours, and so on

Log on to SSH as an administrator, enter the command crontab-e to edit the crontab file, and enter and save the file according to the preceding format.

Crontab example

Run the Command/bin/ls once every 0th minutes of every hour every month:

  1. 0 ***/bin/ls

During October 11, December, execute/usr/bin/backup every 20 minutes from to every day:

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

From Monday to Friday, send a letter to alex@domain.name at PM:

  1. 0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata

Every month at midnight 00:20, 02:20, 04:20 .... Execute echo "haha"

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

Every two hours from PM to AM, AM

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

In hp unix, it is executed every 20 minutes, which indicates: 0, 20, 40 *** instead of */n. Otherwise, a syntax error occurs.

Crontab usage is actually very easy to understand. it is helpful for website and server maintenance, such as regular backup and server optimization.

This article is from "? Pan Songsong? Small blog, please be sure to keep this source http://navyaijm.blog.51cto.com/4647068/816636


Related Article

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.