Linux-crontab and linux-crontab

Source: Internet
Author: User
Tags crontab example nginx server

Linux-crontab and linux-crontab

I have learned a little about crontab before, And I am familiar with it some time ago. I will record it today.

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.

When does crontab need to be used? The following are some good application scenarios:

  • Run a program every minute to check the system running status.
  • Statistics on the business data of the past day are required every early morning.
  • Back up log files every week
  • Back up the database every month
Install crontab

The installation in ubuntu is as follows:

sudo apt-get install cron

 

Time settings
# File format description # -- minute (0-59) # | -- hour (0-23) # | -- Day (1-31) # | -- month (1-12) # | -- week (0-7) (Sunday = 0 or 7) # | # *** executed command

Note:

Indicates the command to be executed from the sixth domain.

 

Crontab command
    crontab [ -u user ] [ -i ] { -e | -l | -r }        (default operation is replace, per 1003.2)    -e    (edit user's crontab)    -l    (list user's crontab)    -r    (delete user's crontab)    -i    (prompt before deleting user's crontab)

 

Crontab example

Restart nginx at every night

30 21 *** service nginx restart

Restart nginx at on May 1, 10, and 22 every month

45 4, 22 ** service nginx restart

Restart nginx at from the first day of every month

45 4 1-10 ** service nginx restart

Restart the nginx server every 2 minutes

*/2 ***** service nginx restart

1-59/2 *** service nginx restart

Restart nginx every hour between PM and PM.

0 23-7/1 *** service nginx restart

Restart nginx every 30 minutes from to every day

0, 30 18-23 *** service nginx restart

0-59/30 18-23 *** service nginx restart

Summary
  • * Indicates matching at any time
  • You can use "A, B, C" to execute commands When A, B, or C is used.
  • You can run the command to represent A to B with "A-B"
  • You can use "*/A" to execute A command every hour.

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.