• 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

      

      

  • 相关阅读:
    用 ArcMap 发布 ArcGIS Server Feature Server Feature Access 服务 SQL Server版
    ArcGIS Server Manager 重置密码
    接口自动化过程中遇到的问题?
    接口自动化的闭环?
    每天有80亿的文件需要存储,你会怎么设计存储和检索?
    数据库之索引
    java之高并发锁
    测试环境搭建
    shell基本语法
    RPC和HTTP
  • 原文地址:https://www.cnblogs.com/ShanCe/p/14368904.html
Copyright © 2020-2023  润新知