VPS侦探论坛

 找回密码
 注册
查看: 5238|回复: 2

cut_nginx_logs脚本不删除过期日志文件目录

[复制链接]
发表于 2013-10-9 14:55:48 | 显示全部楼层 |阅读模式

cut_nginx_logs.sh:
  1. #!/bin/bash
  2. #function:cut nginx log files for lnmp v0.5 and v0.6
  3. #author: http://lnmp.org

  4. #set the path to nginx log files
  5. log_files_path="/data0/www/logs/access/"
  6. log_files_dir=${log_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
  7. #set nginx log files you want to cut
  8. log_files_name=(access)
  9. #set the path to nginx.
  10. nginx_sbin="/usr/local/nginx/sbin/nginx"
  11. #Set how long you want to save
  12. save_days=7

  13. ############################################
  14. #Please do not modify the following script #
  15. ############################################
  16. mkdir -p $log_files_dir

  17. log_files_num=${#log_files_name[@]}

  18. #cut nginx log files
  19. for((i=0;i<$log_files_num;i++));do
  20. mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
  21. done

  22. #delete 7 days ago nginx log files
  23. find $log_files_path -mtime +$save_days -exec rm -rf {} \;

  24. $nginx_sbin -s reload
复制代码
目录结构是这样的: /data0/www/logs/
logs 下面只有 access  和  error  两个目录
/data0/www/logs/access/ 包含目录2013 和文件 access.log


/data0/www/logs/error/nginx_error.log   error目录只有一个
nginx_error.log



/data0/www/logs/access/2013/  包含09 和 10 两个目录(从9月份开始使用此脚本)
9月的目录还健在

怎么清空目录?

[ 本帖最后由 puffbaby 于 2013-10-9 15:09 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-10-9 16:00:50 | 显示全部楼层


脚本会自动删除超过时间的文件,建议手动执行看看,运行过程报错没
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-10-9 17:14:35 | 显示全部楼层

回复 2# 的帖子


文件是删除了,就是文件的目录,也就是时间目录没有删除诶
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-25 03:28 , Processed in 0.025473 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表