帖子内包含图片,需登陆后查看高清大图
您需要 登录 才可以下载或查看,没有帐号?立即注册
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日志切割脚本 使用或转载时请保留版权,谢谢。
该贴已经同步到 湖南站长站的微博 |