Linux的计划任务crontab

概述

crond 是Linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与Windows下的计划任务类似
该文件位于/etc/crontab

操作

命令 作用
$service cron status 查看cron状态
$/etc/init.d/cron start 启动cron
$/etc/init.d/cron stop 关闭cron
$/etc/init.d/cron restart 重启cron
参数 作用
$ crontab -e 修改crontab文件,如不存在自动创建
$ crontab -l 显示crontab文件
$ crontab -r 删除crontab文件
$ crontab -ir 删除crontab文件前提醒用户

格式

每行中包含6个域,前5个指定时间,最后1个指定命令
minute hour day-of-month month-of-year day-of-week user command
简写:m h dom mon dow user command
对应:分钟 小时 月的第几日 月份 周的第几日 命令
合法值为00-59 00-23 01-31 01-12 0-6(0为周日)

  • 参数设置:
    m 为例,其余类推
    m* 时,表示该任务每分钟执行一次
    ma-b 时,表示该任务在 ab 分钟段内执行
    m*/n 时,表示每间隔 n 分钟执行一次
    mabc 时,表示第 abc 分钟要执行

  • 例子:

    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 
    

猜你喜欢

转载自blog.csdn.net/ddfdjffd/article/details/90058864