命令:crontab

crontab是执行定时任务的一个命令。

以下所有描述基于RHEL AS OS

A. 重启crontab服务

service crond restart

B. 任务设定格式描述

minute(0-59) hour(0-23) day(1-31) month(1-12) week(0-6) command

      Opitions Explanation

  1.  * :Is treated as a wild card. Meaning any possible value.
  2.   */5:  Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with another numerical value will change this option.
  3.   2,4,6: Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-clock.
  4.   9-17: Treats for any value between 9 and 17. So if placed in day of month this would be days 9 through 17. Or if put in hours it would be between 9 and 5.
C. 相关设定

1.. 配置crond服务

/etc/crontab

2. 任务设定文件

如 /var/spool/cron/root

该文件不可直接修改,需要使用命令crontab -e

3. 禁止完成任务后发送email

系统默认情况下,会在相关任务出错或者输出数据时候发送一份email给对应用户,禁止发送,只需要在所执行命令后面添加

...>/dev/null 2>&1

记录log,命令后添加

...>/test/xxx.log

D. 实例

30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启lighttpd 。

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重启lighttpd 。

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每周六、周日的1 : 10重启lighttpd 。

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启lighttpd 。

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重启lighttpd 。

* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小时重启lighttpd

* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11点到早上7点之间,每隔一小时重启lighttpd

0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4号与每周一到周三的11点重启lighttpd

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一号的4点重启lighttpd

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值