A-A+

Lnmp下Nginx日志自动切割脚本

2015年03月23日 Linux 评论 3 条 阅读 2,629 次

该脚本会自动切割/home/wwwlogs/目录下所有的log文件

#!/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="/home/wwwlogs/"
log_files_dir=${log_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")

#set the path to nginx.
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save
save_days=30

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

cd $log_files_path
#cut nginx log files
for d in `ls -f *.log`;do
mv ${log_files_path}${d} ${log_files_dir}/$(date -d "yesterday" +"%Y%m%d")_$d
done

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

$nginx_sbin -s reload
标签:

3 条留言  访客:0 条  博主:0 条


    Warning: A non-numeric value encountered in /data/wwwroot/lxy.me/wp-content/themes/Ality/inc/functions/comment-template.php on line 16
  1. avatar 香港vps

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/wwwroot/lxy.me/wp-content/themes/Ality/functions.php on line 249
  2. avatar 寻寻觅博客

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/wwwroot/lxy.me/wp-content/themes/Ality/functions.php on line 249
    • avatar 恋香缘

      Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /data/wwwroot/lxy.me/wp-content/themes/Ality/functions.php on line 249

给我留言