zoukankan      html  css  js  c++  java
  • linux 定时任务 cron

    常用命令:

    crontab参数
            -u:这个参数可以让我们去编辑其他人的crontab,如果没有加上这个参数的话就会开启自己的crontab
            crontab -u 使用者名称
            -l:可以列出crontab的内容
            -r:可以移除crontab
            -e:可以使用系统预设的编辑器,开启crontab
            -i:可以移除crontab,会跳出系统信息让你再次确定是否移除crontab

    格式:

    * * * * * /bin/bash ~/shelltest/mv_and_touch.sh
    

      格式:

    顺序 日期 月份 星期 年(可选)
    取值 0-59 0-59 0-23 1-30(31) 1-12 1-7 1970~2099
    允许特殊字符 , - * / , - * / , - * / , - * / ? L W C , - * / , - *? / L C #  , - * /

    cron 命令:

       /etc/init.d/cron start # 启动 或者 service cron start

       /etc/init.d/cron stop # 停止 service cron stop 

       /etc/init.d/cron restart # 重启 service cron restart

       /etc/init.d/cron reload # 重新加载 写完定时任务后可以使用 

    cron的日志

      /var/log/cron.log

     如果该文件下没有的话:

      1. 修改rsyslog文件::

        vi /etc/rsyslog.d/50-default.conf 

        将  rsyslog  文件中的  #cron.*  前的  #  删掉;

      2. 重启rsyslog 

        service rsyslog restart 

      3. 重启cron

        service cron restart

    参考:

      1. https://blog.csdn.net/ningningjj/article/details/104532157/

      2.https://www.cnblogs.com/dongye95/p/10108696.html

    贴上我测试的,日志按日期分割代码:

    mv_and_touch.sh

    #!/bin/sh
    cd ~/shelltest

    if [ ! -d date_log ]; then
      mkdir date_log
    fi
    if [ ! -s 'access_nginx.log' ]; then
      mv access_nginx.log ~/shelltest/date_log/access_$(date +"%Y-%m-%d_%H:%M:%S")  # 时间一般设为 (date -I)   年-月-日, 这里只是为了看效果加上了 时分秒
      touch access_nginx.log
    else:
      echo 'empty'
    fi

      

      

  • 相关阅读:
    通用二进制格式安装、编译安装过程(以mysql为例)
    linux:网络
    深圳:软通-运维
    深圳:软通-python
    linux:用户管理
    linux:vim
    深圳:卡莱特-售前/售后服务
    linux:基本指令
    linux:安装
    电脑:磁盘扩容
  • 原文地址:https://www.cnblogs.com/ShanCe/p/14368904.html
Copyright © 2011-2022 走看看