Linux Crontab scheduled task

Source: Internet
Author: User

1. Introduction to crontab

The crontab command schedules the execution of some commands at certain intervals.

 

1.1/etc/crontab file

There is a crontab file in the/etc directory, which stores some scheduling programs that are running systematically. Each user can create their own scheduling crontab (in the/var/spool/cron directory ).
The following is the crontab file on my local machine,

[Root @ localhost etc] # Cat/etc/crontab
Shell =/bin/bash
Path =/sbin:/bin:/usr/sbin:/usr/bin
Mailto = root
Home =/

# Run-Parts
01 *** root run-parts/etc/cron. Hourly
02 4 *** root run-parts/etc/cron. daily
22 4 ** 0 root run-parts/etc/cron. Weekly
42 4 1 ** root run-parts/etc/cron. Monthly

 

Ii. crontab instructions

 

2.1 crontab basic syntax

Usage: crontab [-u user] File

Crontab [-u user] [-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)

-S (SELinux context)

 

File is the name of the command file. If this file is specified in the command line, run the crontab command to copy the file to the crontabs directory. If this file is not specified in the command line, the crontab command will accept the commands typed on the standard input (keyboard) and store them in the crontab directory.

To view more detailed syntax and help for crontab, you can use man crontab to view help.

 

2.2 crontab format description

We can use crontab-e to add the command to be executed.

The added command must be in the following format:

* ***/Path of the command to be executed

The first five fields can take an integer to specify when to start working. The sixth field is a string, that is, a command field, which includes the crontab command for scheduling and execution. The fields are separated by spaces and tabs.

 

The first five fields are represented respectively:

Minute: 0-59

Hours: 1-23

Date: 1-31

Month: 1-12

Week: 0-6 (0 indicates Sunday)

 

You can also use some special symbols:

*: Indicates any time

,: Indicates Segmentation

-: Indicates a segment. For example, 1-5 in the second end indicates.

/N: indicates that each n is executed once. For example, in the second segment, */1 indicates that the command is executed every one hour. You can also enter 1-23/1.

 

Some examples:

00, 8, 12, 16 ***/test/command. Sh

30 2 ***/test/command. Sh

10 8, 12, 16 ***/test/command. Sh

10 8, 12, 16 ***/test/command. Sh

10 8, 12, 16 ***/test/command. Sh

 

43 21 *** run

15 05 *** run

0 17 *** execute

0 17 ** 1 run at every Monday

17 **, 3 run at and on every Sunday, Tuesday, and Wednesday.

0-10 17 1 ** from PM to PM every other 1 minute

0 0*1 on Monday 1 and 15

42 4 1 ** executed at on the first day of the month

0 21 ** 1-6 from Monday to Saturday

0, 10, 20, 30, 40, 50 *** run every 10 minutes

*/10 * execute every 10 minutes

* 1 *** run every 1 minute from

0 1 *** execution

0 */1 * execution at every 1 hour

0 * execution at every 1 hour

2 8-20/3 *** run

30 5, ** executed at on the 1st and 15th

 

 

 

 

 

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.