zoukankan      html  css  js  c++  java
  • linux crontab 简述

    os: ubuntu 16.04

    linux crontab 在实际工作中大量使用,这里简单记录下。

    cron服务

    cron 在安装os都是默认安装的,如果发现没有安装,可以 apt 安装,对于 redhat 分支可以使用 yum 安装。

    # ps -ef|grep cron
    root       929     1  0 10:15 ?        00:00:00 /usr/sbin/cron -f
    
    # /etc/init.d/cron 
     * Usage: /etc/init.d/cron {start|stop|status|restart|reload|force-reload}
    
    # systemctl status cron.service
    # systemctl stop cron.service
    # systemctl start cron.service
    # systemctl disable cron.service
    # systemctl enable cron.service
    
    # cat /lib/systemd/system/cron.service 
    [Unit]
    Description=Regular background program processing daemon
    Documentation=man:cron(8)
    
    [Service]
    EnvironmentFile=-/etc/default/cron
    ExecStart=/usr/sbin/cron -f $EXTRA_OPTS
    IgnoreSIGPIPE=false
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    

    常见的一些配置

    1 crobtab 的格式如下:

    # 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
    

    简单记忆为:分时日月周脚本

    2 crontab 查看

    # crontab -l
    
    # crontab -l > /tmp/mycron
    

    3 crontab 编辑

    $ crontab -e
    

    4 crontab 示例

    0 * * * * /bin/echo `date` > /tmp/da
    
    0,15,30,45 * * * * /bin/echo `date` > /tmp/da
    
    0,15,30,45 18-06 * * * /bin/echo `date` > /tmp/da
    
    0,15,30,45 18-06 */2 * * /bin/echo `date` > /tmp/da
    
    0,15,30,45 18-06 */2 * 6 /bin/echo `date` > /tmp/da
    
    00 18 * * * script -c "/apps/log_done.sh >> /apps/log_done.log"
    
    00 18 * * * /apps/log_done.sh >> /apps/log_done.log 2>&1
    
    00 18 * * * /apps/log_done.sh >> /apps/log_done.log 2>&1 &
    
  • 相关阅读:
    各种颜色对应的16进制
    django之旅 1.hello world
    FlexPaper文档在线浏览
    windwos下django 安装配置
    Josn 序列化
    WCF服务
    easy_install遇上Unable to find vcvarsall.bat
    Android开发环境搭建(jdk+eclip+android sdk)
    安卓系统架构图(转)
    windows8和windows server2012不联网安装.net 3.5(包括2.0和3.0)
  • 原文地址:https://www.cnblogs.com/ctypyb2002/p/9792862.html
Copyright © 2011-2022 走看看