crontab 定时写法整理

一、基本格式 : 
    M  H  D  m  d  command 
    分 时  日  月  周   命令 
    第1列  分钟1~59 每分钟用*或者 */1表示 
    第2列  小时1~23(0表示0点) 
    第3列  日期1~31 
    第4列  月份1~12 
    第5列  星期0~6(0表示星期天) 
    第6列  要运行的命令 
    
二、crontab文件的一些例子: 
    */30 * * * * (python /mnt/mmcblk0/linux/execute.py)        #每30分钟运行一次该脚本
    0 0 * * * init 6                                        #每天00:00重启
    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            #每星期六的23 : 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 

三、文件、目录
crontab file [-u user]-用指定的文件替代目前的crontab。 
crontab-[-u user]-用标准输入替代目前的crontab. 
crontab-c dir- 指定crontab的目录。 

四、用户
crontab-1[user]-列出用户目前的crontab. 
crontab-e[user]-编辑用户目前的crontab. 
crontab-d[user]-删除用户目前的crontab. 

猜你喜欢

转载自blog.csdn.net/qq_16224495/article/details/81751266