Linux CentOS

Linux CentOS 6.8 | 7.0 | 7.8 任务调度

crontab 服务

[root@node ~]# service crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
[root@node ~]# /etc/init.d/crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]


1. 编辑 /etc/crontab

[root@node ~]# vim /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# 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

特殊字符:

* 代表任何时间。比如第一个“*”就代表一小时中每分钟都执行一次的意思。
, 代表不连续的时间。比如“0 8,12,16 * * * 命令”,就代表在每天的8点0分,12点0分,16点0分都执行一次命令。
- 代表连续的时间范围。比如“0 5 * * 1-6命令”,代表在周一到周六的凌晨5点0分执行命令。
*/n 代表每隔多久执行一次。比如“*/10 * * * * 命令”,代表每隔10分钟就执行一遍命令。

2.使用crontab指令

用于编辑个人用户定时任务,创建的调度文件存在放 /var/spool/corn/用户名命名的目录下。

参数:

-u: 只有root才能进行这个任务,也即帮其他用户新建/删除crontab工作调度;

-e: 编辑crontab 的工作内容;

-l: 查阅crontab的工作内容;

-r: 删除所有的crontab的工作内容,若仅要删除一项,请用-e去编辑。


文章推荐:

https://blog.csdn.net/qq_30604989/article/details/81146993

https://www.cnblogs.com/mingforyou/p/3930636.html


转载请指明出处!http://www.miselehe.com/article/view/62