• nginx日志按天切割,删除15天日志


    cat cut-nginx-log.sh

    #delete 15 day nginx log
    00 00 * * * /bin/bash /data/script/cut-nginx-log.sh
    [root@ali-idn-pro-nginx-ps01 script]# cat /data/script/cut-nginx-log.sh
    #!/bin/bash
    LOGS_PATH=/data/log/nginx/
    YESTERDAY=$(date -d "yesterday" +%Y%m%d)
    #按天切割日志
    mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access-${YESTERDAY}.log
    mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error-${YESTERDAY}.log
    #向nginx主进程发送USR1信号,重新打开日志文件,否则会继续往mv后的文件写数据的。原因在于:linux系统中,内核是根据文件描述符来找文件的。如果不这样操作导致日志切割失败。
    kill -USR1 `ps axu | grep "nginx: master process" | grep -v grep | awk '{print $2}'`
    #delete 15 day nginx log
    cd ${LOGS_PATH}
    find /data/log/nginx/ -type f -mtime +15 | xargs rm -f
    exit 0

    定时任务

    #delete 15 day nginx log
    00 00 * * * /bin/bash /data/script/cut-nginx-log.sh
    使劲折腾才会有更好的结果!!!! 如有不对请不吝赐教,感谢! 转载请注明出处!
  • 相关阅读:
    SQLite基本(实例FileOrganizer2013.5.12)
    MongoDB常见问题
    Node.js
    Linux安装indicator-china-weather
    Hadoop常见问题
    Hadoop HDFS文件操作
    Ubuntu下载、zsync、安装、常见问题
    Mongo-Hadoop
    Mongo JavaTest
    MongoDB 快速入门
  • 原文地址:https://www.cnblogs.com/huanglingfa/p/14804222.html
Copyright © 2020-2023  润新知