湖南站长站 发表于 2013-2-18 21:39:01

恩集MAPN Nginx日志切割脚本 Apache日志切割脚本

恩集组织旗下的MAPn是本站用过的除军哥的LNMP之外最好用的服务器WEB环境了,其优点就不说了。
在使用过程中,遇到了一个问题——网站的各种日志无法删除
而之前用军哥的LNMP时,军哥就有一个切割Nginx日志的教程,Cut Nginx Logs. 所以我就开始借鉴军哥的这个脚本,捣鼓适用于MAPN的日志切割脚本。
该VPS日志切割脚本适用于:Nginx日志切割 Apache日志切割 Nginx错误日志切割 Apache错误日志切割
整个脚本如下
#!/bin/bash
#function:cut nginx / Apache log files for MAPn Based on LNMP Script
#author: http://lnmp.org & http://www.hnzzz.net

#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 nginx log files you want to cut
log_files_name=(hnzzz.net.error hnzzz.net)
#set the path to nginx.
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save
save_days=90

############################################
#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 30 days ago nginx log files
find $log_files_path -mtime +$save_days -exec rm -rf {} \;

############################################
#   Restart your nginx and apache service#
############################################
#set the path to MAPN.
mapn_sbin="/etc/init.d/httpd"
$mapn_sbin restart
其中log_files_name=(hnzzz.net.error hnzzz.net) 括号内为你想要切割的日志名称,结尾不能带 .log
以上脚本文件修改自军哥 Nginx日志切割脚本 使用或转载时请保留版权,谢谢。


http://bbs.hnzzz.net/xwb/images/bgimg/icon_logo.png 该贴已经同步到 湖南站长站的微博
页: [1]
查看完整版本: 恩集MAPN Nginx日志切割脚本 Apache日志切割脚本