我的nginx多server日志分割脚本

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# !/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