zoukankan      html  css  js  c++  java
  • centos crontab定时任务用法

    centos crontab定时任务用法

    一、安装crond服务

    yum -y update
    yum -y install cronie yum-cron

    二、crontab任务语法

    crontab任务配置基本格式:
    *   *  *  *  *  command
    第1列表示分钟0~59 每分钟用 * 或者 */1 表示
    第2列表示小时0~23(0表示0点)
    第3列表示日期1~31
    第4列表示月份1~12
    第5列标识号星期0~6(0,7都可表示星期天)
    第6列要运行的命令或执行shell脚本
    a、crontab -e,添加如下内容:
    */1 * * * * sh && echo "dd" >> /logs/cron-cc.log
    */1 * * * * sleep 30 && echo "cc" >> /logs/cron-cc.log
    
    b、重启crond
    systemctl reload crond
    systemctl restart crond
    
    c、查看当前用户定时任务
    crontab -l
    
    d、通过日志查看是否生效
    tail -f /logs/cron-cc.log
     
     
    (1)基本格式 :
    *  *  *  *  *  command
    分 时 日 月 周 命令
    第1列表示分钟1~59 每分钟用*或者 */1表示
    第2列表示小时1~23(0表示0点)
    第3列表示日期1~31
    第4列表示月份1~12
    第5列标识号星期0~6(0表示星期天)
    第6列要运行的命令
    (2)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 

     

  • 相关阅读:
    CodeForces 1105D-暴力BFS
    POJ 1258 Agri-Net (最小生成树)
    POJ 1251 Jungle Roads (最小生成树)
    hiho 1097 最小生成树一·Prim算法 (最小生成树)
    Codeforces 544E K Balanced Teams (DP)
    Codeforces 408D Long Path (DP)
    PTA L1题目合集(更新至2019.3)
    HDOJ 3308 LCIS (线段树)
    HDOJ 1698 Just a Hook (线段树)
    HDOJ 4267 A Simple Problem with Integers (线段树)
  • 原文地址:https://www.cnblogs.com/adolfmc/p/12006174.html
Copyright © 2011-2022 走看看