华域联盟 linux shell nginx多server日志分割脚本分享

nginx多server日志分割脚本分享

1,配置多个server日志只要在$website变量增加并用空格分开就行。
2,循环创建日志目录
3,分割后用xz 压缩,当然没安装可以用gzip bzip2等等。
4,注意我配置nginx日志文件名为 "access_{{站点网站}}.log" "error_{{站点网站}}.log"

复制代码 代码如下:

# !/usr/bin/bash

log_dir="/usr/local/nginx/logs"

back_log_dir="/disk110/nginx_log"

time=`date +%Y%m%d-%H:%M:%S`  

website="www.test1.com www.test2.com www.test3.com";

for i in $website
do
 if [ ! -d ${back_log_dir}/${i} ] then
  mkdir ${back_log_dir}/${i}
 fi
done 

for i in $website
do
 if [ -s ${log_dir}/access_${i}.log ] then
  mv ${log_dir}/access_${i}.log ${back_log_dir}/${i}/access_${time}.log
 fi

 if [ -s ${log_dir}/error_${i}.log  ] then
  mv ${log_dir}/error_${i}.log ${back_log_dir}/${i}/error_${time}.log
 fi

done

kill -USR1 `cat  /usr/local/nginx/logs/nginx.pid`

for i in $website
do
 if [ -s ${back_log_dir}/${i}/access_${time}.log ] then
  xz  ${back_log_dir}/${i}/access_${time}.log
 fi

 if [ -s ${back_log_dir}/${i}/error_${time}.log ] then
  xz  ${back_log_dir}/${i}/error_${time}.log
 fi

done

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » nginx多server日志分割脚本分享

转载请保留出处和原文链接:https://www.cnhackhy.com/15650.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部