「nginx入門」複数サイトのログを出力する方法
設定内容:
# !/usr/bin/bash
log_dir="/usr/local/nginx/logs"
back_log_dir="/datadisk/nginx_log"
time=`date +%Y%m%d-%H:%M:%S`
cfthp="www.sample1.com www.sample2.com www.sample3.com";
for i in $cfthp
do
if [ ! -d ${back_log_dir}/${i} ]
then
mkdir ${back_log_dir}/${i}
fi
done
for i in $cfthp
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 $cfthp
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