Learning--crontab for Linux

Source: Internet
Author: User

Prior to understand a little crontab, the previous period of time more idle, familiar with a bit, today summary record.

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.

When do I need to use crontab? Here are a few good scenarios.

    • A program needs to be executed every minute to check the system running status
    • Need to count business data for the past day in the wee hours of the day
    • Log files need to be backed up every week
    • Need to back up the database every month
Installing crontab

The installation in Ubuntu system is as follows:

sudo Install cron

Time setting
# File Format Description #  --minutes (0|  --Hours (0| |  --Day   (1|  | | --month   (1|  | | | --Week (07) (Sunday= | | | | |  * * * * * Command executed

Note:

    1. In the "Day of the Week" (fifth field), 0 and 7 are considered Sunday.
    2. Not very intuitive to use: if the date and week are set simultaneously, then one of the conditions is satisfied, the instruction will be executed.
    3. The first 5 fields are called the time of day and week , can be convenient for personal memory.

From the sixth field, indicate the command to execute.

crontab command
    crontab [-u user] [-i] {-e |-L |-r        }1003.2)    -E    (edit users CR Ontab)-    l    (list user's crontab)    -R    (delete user's crontab)    -I (Prompt before deleting user's crontab)

crontab Example

Restart Nginx every 21:30

* * * Service Nginx restart

1, 10, 22nd of 4:45 restart Nginx

4 1,10,22 * * Service Nginx restart

1-10 days a month 4:45 restart Nginx

4 1-10 * * Service Nginx restart

Restart the Nginx server every 2 minutes

*/2 * * * * Service Nginx restart

1-59/2 * * * * Service Nginx restart

From 11 o'clock to 7 in the morning, restart nginx every hour.

0 23-7/1 * * * Service Nginx restart

Restart Nginx every 30 minutes from 18:00 to 23:00 every day

0,30 18-23 * * * Service Nginx restart

0-59/30 18-23 * * * Service Nginx restart

Summary
    • * Indicates any time to match
    • You can use "A,b,c" to represent A or B or C when executing A command
    • You can use "A-B" to represent the command
    • You can use "*/a" to indicate that every A-minute (hour, etc.) command is executed

Learning--crontab for Linux

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.