nginx多server日志分割腳本分享
1,配置多個server日志只要在$website變量增加并用空格分開就行。
2,循環(huán)創(chuàng)建日志目錄
3,分割后用xz 壓縮,當然沒安裝可以用gzip bzip2等等。
4,注意我配置nginx日志文件名為 "access_{{站點網(wǎng)站}}.log" "error_{{站點網(wǎng)站}}.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
相關(guān)文章
詳解git無法pull倉庫refusing to merge unrelated histories
這篇文章主要介紹了詳解git無法pull倉庫refusing to merge unrelated histories的相關(guān)資料,需要的朋友可以參考下2017-06-06shell 通過makefile傳參給c語言的實現(xiàn)示例
本文主要介紹了shell 通過makefile傳參給c語言的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03linux下自動備份MySQL數(shù)據(jù)并上傳到FTP上的shell腳本
linux下自動備份MySQL數(shù)據(jù)并上傳到FTP上的shell腳本,需要的朋友可以參考下2013-01-01