Nginx multi-server log split script sharing _linux Shell

Source: Internet
Author: User

1, configure multiple server logs as long as the $website variable is incremented and separated by a space.
2, looping to create the log directory
3, after the split with XZ compression, of course, can not be installed with Gzip bzip2 and so on.
4, note that I configure the Nginx log file named "access_{{site}}.log" "error_{{Site site}}.log"

Copy Code code as follows:

#!/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
Todo
if [!-D ${back_log_dir}/${i}]
Then
mkdir ${back_log_dir}/${i}
Fi
Done

For I in $website
Todo
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
Todo
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.