• nginx日志按天切割


    要求:以天为单位进行日志文件的切割,如host.access_20150915.log, 日志保留最近10天的, 超过10天的日志文件则进行删除.

    nginxcutlogs.sh脚本内容:

    #!/bin/bash
    # move host.access.log to host.access_yyyymmdd.log
    logs_path="/home/dev/nginx/logs/"
    mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d").log
    mv ${logs_path}host.access.log ${logs_path}host.access_$(date -d "yesterday" +"%Y%m%d").log
    kill -USR1 `cat /home/dev/nginx/logs/nginx.pid`
    # delete all host.access_20xxxxxx.log which overtime 20 days
    find ${logs_path} -name 'host.*.log' -type f -mtime +20 -exec rm {} ;
    find ${logs_path} -name 'access_*.log' -type f -mtime +20 -exec rm {} ;

    使用crontab进行把上述脚本发布到定时任务, 每天凌晨0点0分1秒定时执行脚本

    1 0 * * * /bin/bash /home/dev/nginx/nginxcutlogs.sh

    效果:

  • 相关阅读:
    车载以太网 doip someip
    pytest
    lauterbach
    django
    django info
    Linux上加了kdb,softlock
    jenkins war
    Ubuntu 编译安装 Python3.6.8 没有正确编译 sqlite3 的问题
    HTB靶场记录之Bank
    HTB靶场记录之SolidState
  • 原文地址:https://www.cnblogs.com/xulan0922/p/9224135.html
Copyright © 2020-2023  润新知