Linux Scheduled Tasks Crontab notes and summaries (2) Basic composition and configuration of Crontab

Source: Internet
Author: User

"The basic composition of Crontab"

system service CROND: Refreshes the scheduled task from the configuration file every minute

configuration file : Set up timed tasks by file mode

Configuration Tool crontab: Use to adjust timed tasks

Configuration file format for profile

* * * * * COMMAND

The first *: minutes 0-59,* means to execute every minute

Second *: hours 0-23

Third one *: date 1-31

Fourth one *: month 1-12

Fifth *: week 0-7 (0 or 7 = Sunday)

"Example 1" 21:30 restart Apache per night

* * * Service httpd restart

"Example 2" 1, 10, 22nd of 4:45 restart Apache

1,10,22 * * Service httpd restart

"Example 3" 4:45 restart Apache per month from 1 to 10th

1-10 * * Service httpd restart

"Example 4" restarts Apache every two minutes (no previous conditions)

*/2 * * * * Service httpd restart

"Example 5" odd minutes per hour restart Apache

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

Start restart at 1 minutes

(even 0-58/2)

"Example 6" from 11 o'clock to 7 a.m., every 1 hours (front conditional) Restart Apache

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

Note: Minutes with 0, if used *, means 23 to 7 points any one minute to execute, obviously not the result we want

"Example 7" restarts Apache every 30 minutes from 18:00 to 23:00 daily (with conditions in front)

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

Or

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

Summary

①* means matches at any time.

② can use "a,b,c" to represent A or B or C when executing commands

③ can use a "a-B" to represent a to a/C when executing a command

④ can use "*/a" to execute commands once per A-minute (hour, etc.)

"Use of crontab tools"

Crontab Help Information

Crontab----help

① View a list of scheduled tasks for a user (Dee)

- u Dee

② Modifying a user's (Dee) scheduled task

CRONTAB-E-U Dee

With: Wq save exit (seemingly Ubuntu system exit Edit Schedule task to be more complicated)

③ View the resulting final scheduled task file

-/var/spool/cron

Use

Tail-f/var/log/cron

View Crontan's logs

Linux Scheduled Tasks Crontab notes and summaries (2) Basic composition and configuration of Crontab

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.