puffbaby 发表于 2013-10-9 14:55:48

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

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

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

############################################
#Please do not modify the following script #
############################################
mkdir -p $log_files_dir

log_files_num=${#log_files_name[@]}

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

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

$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 编辑 ]

licess 发表于 2013-10-9 16:00:50

脚本会自动删除超过时间的文件,建议手动执行看看,运行过程报错没

puffbaby 发表于 2013-10-9 17:14:35

回复 2# 的帖子

文件是删除了,就是文件的目录,也就是时间目录没有删除诶
页: [1]
查看完整版本: cut_nginx_logs脚本不删除过期日志文件目录