湖南站长论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1096|回复: 0

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

[复制链接]
发表于 2013-2-18 21:39:01 | 显示全部楼层 |阅读模式

帖子内包含图片,需登陆后查看高清大图

您需要 登录 才可以下载或查看,没有帐号?立即注册

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

#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[i]}.log ${log_files_dir}/${log_files_name[i]}_$(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

其中
[Shell] 纯文本查看 复制代码
log_files_name=(hnzzz.net.error hnzzz.net)
括号内为你想要切割的日志名称,结尾不能带 .log
以上脚本文件修改自军哥 Nginx日志切割脚本 使用或转载时请保留版权,谢谢。



                               
登录/注册后可看大图
该贴已经同步到 湖南站长站的微博
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|湖南站长论坛

GMT+8, 2024-4-29 16:15 , Processed in 0.201496 second(s), 10 queries , Gzip On, MemCached On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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