linux 利用crontab 来设置定时任务



vim /etc/crontab

# 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


1,crontab的格式为上.

2,下面用例子的形式来说明其作用

crontab范例
                   * * * * * # 分 时 天 月 星期

    每五分钟执行  */5 * * * *  

    每小时执行     0 * * * *

    每天执行       0 0 * * *

    每周执行       0 0 * * 0

    每月执行       0 0 1 * *

    每年执行       0 0 1 1 *





2,完成好之后 启动crond服务

service crond start    //启动服务
service crond stop     //关闭服务
service crond restart  //重启服务
service crond reload   //重新载入配置
service crond status   //查看服务状态





3,小示例


*/5  *  *  *  * root echo `date`>>/root/log 

service crond start    //启动服务

启动之后,每隔5分钟就会向/root/log中写入时间







猜你喜欢

转载自indinna1.iteye.com/blog/2283846