crontab简介:
crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令。该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行。通常,crontab储存的指令被守护进程激活, crond常常在后台运行,每一分钟检查是否有预定的作业需要执行。这类作业一般称为cron jobs。
系统环境:CentOS 6.8
安装crontab命令(yum安装)
# yum -y install vixie-cron
执行结果(crontabs作为依赖已经安装)
Installed:
cronie.x86_64 0:1.4.4-15.el6_7.1
Dependency Installed:
cronie-anacron.x86_64 0:1.4.4-15.el6_7.1 crontabs.noarch 0:1.10-33.el6 postfix.x86_64 2:2.6.6-6.el6_7.1
Complete!
查看服务
# /etc/init.d/crond start //启动服务
# /etc/init.d/crond stop //关闭服务
# /etc/init.d/crond restart //重启服务
# /etc/init.d/crond reload //重新载入配置
# /etc/init.d/crond status //查看crontab服务状态
crontab命令举例
30 5 * * 6 find /var/ -name "mysql-bin.*" -mtime +5 -exec rm -f {} \; #每个周六的5:30,查找mysql-bin.*的文件,从这天往前5天的都删除
* * * * * * [user] [command]
- - - - - -
| | | | | |
| | | | | + year [optional]
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)