手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >nginx多server日志分割脚本分享
nginx多server日志分割脚本分享
摘要:1,配置多个server日志只要在$website变量增加并用空格分开就行。2,循环创建日志目录3,分割后用xz压缩,当然没安装可以用gzi...

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日志分割脚本分享】相关文章:

win下调用putty执行命令脚本分享

linux Nginx 日志脚本

centos/rhel下实现nginx自启动脚本实例

ftp自动上传脚本分享

linux中mysql备份shell脚本代码

Linux服务器硬件运行状态及故障邮件提醒的监控脚本分享

mysql源码安装脚本分享

shell监控脚本 准备工作分享

从apnic提取ip信息脚本分享

自动生成linux网卡配置脚本分享

精品推荐
分类导航