crontab是linux系统常用的定时器,具体怎么用呢?
1 查看crontab文件内容
通过命令 cat /etc/crontab我们可以查看crontab具体内容
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# 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
其中最后一行5个星在内容中有详细的解释,具体用法如下:
星号(*):代表任何值,如第一个字段为星号,则表示在满足其它字段的制约条件后每分钟都执行该命令操作。
逗号(,):可以用逗号隔开的值指定一个列表范围,例如 1,2,5,7
中杠(-):表示一个整数范围,例如“2-6”表示“2,3,4,5,6”
正斜线(/):表示执行的频率,例如“0-23/3”表示每两小时执行一次。
2 具体例子
#当天23点,第二天0点到7点每隔一分钟执行一次
* 23,00-07/1 * * * /bin/sh /home/omc.h.sh
#四月份每周的周到周三11点执行脚本
* 00 11 * 4 1-3 /bin/sh /home/omc/h.sh
3 其他常用命令
#安装服务
yum install crontabs
# 启动服务
/sbin/service crond start
#关闭服务
/sbin/service crond stop
#重启服务
/sbin/service crond restart
#重新载入配置
/sbin/service crond reload
感谢您的浏览!