centos下crontab运行定时任务_CentOS下crontab运行定时任务的简单示例

更新时间:2019-11-19    来源:CentOS    手机版     字体:

【www.bbyears.com--CentOS】


首先,打开命令行。如果没有安装crontab的话

1,先安装crontab:

yum install crontabs

说明:

/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
/sbin/service crond status //察看当前crond运行状态

2,以普通用户登录linux系统。运行crond,确保crond当前正在运行


/sbin/service crond start //启动服务

3,进入到crontab的VI编译器中

crontab –e

说明:系统默认的编辑器是VIM,如果不是请加上以下shell:


EDITOR=vi
export EDITOR

基本格式:

* *  *  *  *  command
分 时 日 月 周  命令

4,打开VI编译器后,输入一下内容

*/1 * * * * date >> $HOME/test1.txt

保存并且退出,esc+shift+;


5,到这里,在你桌面的Home文件夹就会多出一个文件夹

如果不行的话,重启一下

su root
cd /etc/init.d
./crond restart

打开桌面上的Home文件,里面就会有一个test.txt文件,打开就能看到每隔一分钟就会写入时间


crontab规则详细实例

1、每天6:00执行

0 6 * * * root /home/www.111cn.net/osyunwei.sh

2、每周六凌晨4:00执行

0 4 * * 6 root /home/www.111cn.net/osyunwei.sh

3、每周六凌晨4:05执行

5 4 * * 6 root /home/www.111cn.net/osyunwei.sh

4、每周六凌晨4:15执行

15 4 * * 6 root /home/www.111cn.net/osyunwei.sh

5、每周六凌晨4:25执行

25 4 * * 6 root /home/www.111cn.net/osyunwei.sh

6、每周六凌晨4:35执行

35 4 * * 6 root /home/www.111cn.net/osyunwei.sh

7、每周六凌晨5:00执行

5 * * 6 root /home/www.111cn.net/osyunwei.sh

8、每天8:40执行

40 8 * * * root /home/www.111cn.net/osyunwei.sh

9、每天8:30执行

30 8 * * * root /home/www.111cn.net/osyunwei.sh

10、每周一到周五的11:41开始,每隔10分钟执行一次

41,51 11 * * 1-5   root /home/www.111cn.net/osyunwei.sh

1-59/10 12-23 * * 1-5   root /home/www.111cn.net/osyunwei.sh

11、在每天的10:31开始,每隔2小时重复一次

31 10-23/2 * * * root   /home/www.111cn.net/osyunwei.sh

12、每天15:00执行

0 15 * * *  root /home/www.111cn.net/osyunwei.sh

13、每天的10:30开始,每隔2小时重复一次

30 10-23/2 * * * root  /home/www.111cn.net/osyunwei.sh

14、每天15:30执行

30 15 * * *  root /home/www.111cn.net/osyunwei.sh

15、每天17:50执行

50 17 * * *  root /home/www.111cn.net/osyunwei.sh

16、每天8:00执行

0 8 * * *  root  /home/www.111cn.net/osyunwei.sh

17、每天18:00执行

0 18 * * *  root  /home/www.111cn.net/osyunwei.sh

18、每天8:30执行

系统运维 www.111cn.net 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接

30 8 * * *  root  /home/www.111cn.net/osyunwei.sh

19、每天20:30

30 20 * * *  root /home/www.111cn.net/osyunwei.sh

20、每周一到周五2:00

0 2 * * 1-5 root /home/www.111cn.net/osyunwei.sh

21、每周一到周五9:30

30 9 * * 1-5 root /home/www.111cn.net/osyunwei.sh

22、每周一到周五8:00,每周一到周五9:00

0 8,9 * * 1-5  root /home/www.111cn.net/osyunwei.sh

23、每天23:59

59 23 * * *  root  /home/www.111cn.net/osyunwei.sh

24、每周六23:59

59 23 * * 6  root    /home/www.111cn.net/osyunwei.sh

25、每天0:30

30 0 * * *  root  /home/www.111cn.net/osyunwei.sh

26、每周一到周五9:25到11:35之间、13:00到15:00之间,每隔10分钟运行一次

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

5-59/10  10 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

5,15,25,35  11 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

*/10  13-15 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

27、每周一到周五8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分别执行一次

30,50 8 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

30 9 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

*/30 10-11 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

30 13 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

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

28、每天23:50执行

50 23 * * *  root  /home/www.111cn.net/osyunwei.sh

29、每天10:00、16:00执行

0 10,16 * * *  root /home/www.111cn.net/osyunwei.sh

30、每天5:30执行

30 5 * * *  root  /home/www.111cn.net/osyunwei.sh

31、每周一到周五9:30执行

30 9 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

32、每周一到周五13:00执行

0 13 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

33、每天7:51执行

51 7 * * *  root /home/www.111cn.net/osyunwei.sh

34、每天7:53、12:40分别执行一次

53 7 * * *  root /home/www.111cn.net/osyunwei.sh

40 12 * * *  root /home/www.111cn.net/osyunwei.sh

35、每天7:55执行

55 7 * * *  root  /home/www.111cn.net/osyunwei.sh

36、每天8:10、16:00、20:00分别执行一次

10 8 * * *  root  /home/www.111cn.net/osyunwei.sh

0 16 * * *  root  /home/www.111cn.net/osyunwei.sh

0 20 * * *  root  /home/www.111cn.net/osyunwei.sh

37、每天7:57、8:00分别执行一次

57 7 * * *  root  /home/www.111cn.net/osyunwei.sh

0 8 * * *  root  /home/www.111cn.net/osyunwei.sh

本文来源:http://www.bbyears.com/caozuoxitong/80002.html

热门标签

更多>>

本类排行