zoukankan      html  css  js  c++  java
  • 使用crontab定时任务 分类: ubuntu 2014-03-13 11:45 194人阅读 评论(0) 收藏

    crontab -e  编辑


    查看任务是否在运行:tail -f /var/log/syslog

    出现类似的信息:

    Apr 26 21:17:01 example CRON[18055]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

    service crond start //启动服务  
    service crond stop //关闭服务  
    service crond restart //重启服务  
    service crond reload //重新载入配置 

    基本格式 :

    *  *  *  *  *  command
    分 时 日 月 周 命令
    第1列表示分钟1~59 每分钟用*或者 */1表示
    第2列表示小时1~23(0表示0点)
    第3列表示日期1~31
    第4列表示月份1~12
    第5列标识号星期0~6(0表示星期天)

    第6列要运行的命令

    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。
    * */1 * * * /usr/local/etc/rc.d/lighttpd restart
    每一小时重启apache
    * 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
    使用权限 : 所有使用者
    使用方式 :
    crontab file [-u user]-用指定的文件替代目前的crontab。
    crontab-[-u user]-用标准输入替代目前的crontab.
    crontab-1[user]-列出用户目前的crontab.
    crontab-e[user]-编辑用户目前的crontab.
    crontab-d[user]-删除用户目前的crontab.
    crontab-c dir- 指定crontab的目录。 


    参数 :
    crontab -e : 编辑时程表
    crontab -r : 删除目前的时程表
    crontab -l : 列出目前的时程表

  • 相关阅读:
    快速搞懂.NET 5/.NET Core应用程序的发布部署
    .NET 5 程序高级调试-WinDbg
    mmap出现 Permission denied
    Java int和integer有什么区别 (mybatis踩坑)
    NodeJS mysql timestamp 数据插入失败的问题
    mysql case when 用法
    postcss 源码解析以及运用
    rust漫游
    关于接口设计的思考--我们真的需要这么多入参吗
    详解apollo的设计与使用
  • 原文地址:https://www.cnblogs.com/think1988/p/4627922.html
Copyright © 2011-2022 走看看