Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Crontab scheduled task

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Crontab (scheduled task operation)

Edit command: crontab-e

View command: crontab-l

# For details see man 4 crontabs

# Example of job definition:

#.-minute (0-59)

# |.-hour (0-23)

# | |.-day of month (1-31)

# |.-month (1-12) OR jan,feb,mar,apr...

# |.-day of week (0-6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |

# * user-name command to be executed

The format is as follows:

Minute hour day month week user-name command

Minute--- minutes (0-59)

Hour- hours (0-23)

Day- date (1-31)

Month--- month (January-December)

Week---- week (0-6) / / 0 represents Sunday

In addition to numbers, there are several special symbols, namely "*", "/" and "-", * represents all the numbers in the range of values, "/" represents each, "* / 5" means every five units, "-" represents from a number to a number, "," separate several discrete numbers. Here are a few examples:

Example:

1 * / tmp/test.sh

Indicates that the script is executed at the first minute of each hour

2 3 * / tmp/test.sh

Indicates that the script is executed at 3: 02 every day

1 1 * * 0 / tmp/test.sh

Represents the execution of the script at 01:01 every week

1 1 1 * / tmp/test.sh

Represents the execution of the script at 01:01 every month

It is easier to make the mistake of doing the first minute of each hour once per minute. Note the difference between the two:

1 * / tmp/test.sh

Indicates that the script is executed at the first minute of each hour

* / 1 * / tmp/test.sh

Represents the execution of the script every minute

So keep in mind the difference brought about by the symbol "/" here.

The usage of "-":

0 10 * * 1-3 / tmp/test.sh

It means to execute the script at 10:00 every Monday through Wednesday morning.

0 10 * 1, 3, 5 / tmp/test.sh

It means to execute the script at 10:00 on Monday, Wednesday and Friday every week.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report