Linux Scheduled Task Crontab example tutorial

Source: Internet
Author: User
Tags crontab example

Description: Crontab is a tool that executes a program at a fixed time in a Linux system, similar to a Task scheduler in a Windows system

Here's a detailed example of how to use Crontab in a Linux system

Operating System: Centos

First, install the crontab

Yum Install Vixie-cron #安装

Chkconfig Crond on #设为开机启动, first install chkconfig (yum install chkconfig)

Service Crond Start #启动

Service Crond Stop #停止

/etc/rc.d/init.d/crond Restart #重启

/etc/rc.d/init.d/crond Reload #不中断服务, re-loading configuration

Ii. set up a task plan

/home/www.osyunwei.com/osyunwei.sh #要自动执行的脚本程序路径

chmod +x/home/www.osyunwei.com/osyunwei.sh #对脚本文件添加执行权限, otherwise cannot be executed

Vi/etc/crontab #编辑配置文件, adding content on the last line

1 * * * root/home/www.osyunwei.com/osyunwei.sh #表示每天凌晨1点30执行备份

: wq! #保存退出

System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link

/etc/rc.d/init.d/crond Restart #重启

Note:

System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link

Crontab file Format:

Minute hour day month weekday username command

minute: Minute, value is 0-59

Hour: Hour with a value of 1-23

Day: Days with a value of 1-31

Month: The value is 1-12

Weekday: Week, value 0-6 (0 for Sunday, 1 for Monday, etc.)

Username: The user to execute the program is generally set to root

Command: Program path to execute (set to absolute path) for example:/home/www.osyunwei.com/osyunwei.sh

Attached: detailed examples of crontab rules

1, Daily 6:00 execution

0 6 * * * root/home/www.osyunwei.com/osyunwei.sh

2, every Saturday 4:00 to execute

0 4 * * 6 root/home/www.osyunwei.com/osyunwei.sh

3, every Saturday 4:05 to execute

5 4 * * 6 root/home/www.osyunwei.com/osyunwei.sh

4, every Saturday 4:15 to execute

4 * * 6 root/home/www.osyunwei.com/osyunwei.sh

5, every Saturday 4:25 to execute

4 * * 6 root/home/www.osyunwei.com/osyunwei.sh

6, every Saturday 4:35 to execute

4 * * 6 root/home/www.osyunwei.com/osyunwei.sh

7, every Saturday 5:00 to execute

5 * * 6 root/home/www.osyunwei.com/osyunwei.sh

8, Daily 8:40 execution

8 * * * root/home/www.osyunwei.com/osyunwei.sh

9, Daily 8:30 execution

8 * * * root/home/www.osyunwei.com/osyunwei.sh

10, every Monday to Friday, starting 11:41, every 10 minutes to execute

41,51 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

1-59/10 12-23 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

11. Repeat every 2 hours, starting at 10:31 every day.

10-23/2 * * * root/home/www.osyunwei.com/osyunwei.sh

12, Daily 15:00 execution

0 * * * root/home/www.osyunwei.com/osyunwei.sh

13, starting 10:30 every day, repeat every 2 hours

10-23/2 * * * root/home/www.osyunwei.com/osyunwei.sh

14, Daily 15:30 execution

* * * * root/home/www.osyunwei.com/osyunwei.sh

15, Daily 17:50 execution

* * * * root/home/www.osyunwei.com/osyunwei.sh

16, Daily 8:00 execution

0 8 * * * root/home/www.osyunwei.com/osyunwei.sh

17, Daily 18:00 execution

0 * * * root/home/www.osyunwei.com/osyunwei.sh

18, Daily 8:30 execution

System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link

8 * * * root/home/www.osyunwei.com/osyunwei.sh

19, every day 20:30

* * * * root/home/www.osyunwei.com/osyunwei.sh

20, every Monday to Friday 2:00

0 2 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

21, every Monday to Friday 9:30

9 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

22, every Monday to Friday 8:00, every Monday to Friday 9:00

0 8,9 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

23, every day 23:59

* * * * root/home/www.osyunwei.com/osyunwei.sh

24, every Saturday 23:59

* * 6 root/home/www.osyunwei.com/osyunwei.sh

25, every day 0:30

0 * * * root/home/www.osyunwei.com/osyunwei.sh

26. Run every 10 minutes from Monday to Friday from 9:25 to 11:35, between 13:00 and 15:00

25,35,45,55 9 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

5-59/10 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

5,15,25,35 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

*/10 13-15 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

27. Execute once every Monday to Friday 8:30, 8:50, 9:30, 10:00, 10:30, 11:00, 11:30, 13:30, 14:00, 14:30, 5:00, respectively

30,50 8 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

9 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

*/30 10-11 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

* * 1-5 root/home/www.osyunwei.com/osyunwei.sh

0,30 14-15 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

28, Daily 23:50 execution

* * * * root/home/www.osyunwei.com/osyunwei.sh

29, Daily 10:00, 16:00 execution

0 10,16 * * * root/home/www.osyunwei.com/osyunwei.sh

30, Daily 5:30 execution

5 * * * root/home/www.osyunwei.com/osyunwei.sh

31, every Monday to Friday 9:30 to execute

9 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

32, every Monday to Friday 13:00 to execute

0 * * 1-5 root/home/www.osyunwei.com/osyunwei.sh

33, Daily 7:51 execution

Wuyi 7 * * * root/home/www.osyunwei.com/osyunwei.sh

34, each day 7:53, 12:40 to perform one time

7 * * * root/home/www.osyunwei.com/osyunwei.sh

* * * * root/home/www.osyunwei.com/osyunwei.sh

35, Daily 7:55 execution

7 * * * root/home/www.osyunwei.com/osyunwei.sh

36, each day 8:10, 16:00, 20:00 to perform one time

8 * * * root/home/www.osyunwei.com/osyunwei.sh

0 * * * root/home/www.osyunwei.com/osyunwei.sh

0 * * * root/home/www.osyunwei.com/osyunwei.sh

37, each day 7:57, 8:00 to perform one time

7 * * * root/home/www.osyunwei.com/osyunwei.sh

0 8 * * * root/home/www.osyunwei.com/osyunwei.sh

At this point, the Linux scheduled task crontab instance is completed in a detailed tutorial

Transfer from http://www.osyunwei.com/archives/5039.html

Linux Scheduled Task Crontab example tutorial

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.