priess1314 发表于 2019-1-29 16:19:31

crontab 计划任务使用示例

crontab是Linux最常用的 计划任务服务

参数

*  *  *  *  *  command

分  时  日    月 周  命令

编辑计划任务列表

crontab -e

增加内容:

每5分钟执行命令

*/5 * * * * 命令

每天的 23点到 7点 每隔1小时执行命令

* 23-7/1 * * * 命令



特别注意的一点. 有的用户并没有启动crontab服务 也没有加入开机启动的!

因此需要:
service crond start    (有的是service cron start)
或者
/etc/rc.d/init.d/crond start
加入开机自动启动:
chkconfig --level 35 crond on




网上例子

crontab文件的一些例子:

30 21 * * * /usr/local/etc/rc.d/lighttpd restart

上面的例子表示每晚的21:30重启apache。

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart

上面的例子表示每月1、10、22日的4 : 45重启apache。

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart

上面的例子表示每周六、周日的1 : 10重启apache。

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart

上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart

上面的例子表示每星期六的11 : 00 pm重启apache。

0 */1 * * * /usr/local/etc/rc.d/lighttpd restart

每一小时重启apache

0 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart

晚上11点到早上7点之间,每隔一小时重启apache

0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart

每月的4号与每周一到周三的11点重启apache

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart

一月一号的4点重启apache

页: [1]
查看完整版本: crontab 计划任务使用示例