No longer worry about log files too large: mooon-server Common Log Scrolling script

Source: Internet
Author: User
Tags file size

log_rotater.sh

#!/bin/sh

# writed by Yijian on 2012/7/22

# This script feature:

# 1 Implementation of a common log scrolling by size

# 2 requires a log file extension of ". Log", otherwise please modify the code slightly

# 3 supports the processing of log files in multiple directories, and if this function is required,

# You must enable the Dirs_list parameter

#

# Why do you write such a thing?

# A: Because in daily life, the program output redirection is often found,

# or the output of the script, if not handled, can cause

# A single file is too large to even fill up the entire disk, and each set of scripts

# Write a log scrolling logic repeatedly, it's obviously boring,

# Even some people do not bother to do processing, a long time, you will find a huge

# log file, this script hopefully can help solve this problem so that everyone has no

Worries

#

# Use Method:

# 1 Copy the script to the directory where the log files are located,

# then start the script in Nohup/log_rotater.sh >/dev/null &, and so on.

# 2 In addition to the above method, can also be log_rotater.sh any directory,

# But this time, you should change the value of Backup_dir to the directory where the log files are located

#

# sudo dpkg-reconfigure Dash

# New version Ubuntu defaults to using the dash as the shell,

# This shell is weak, does not support arrays, and so on, but fast,

# The following methods can be used to detect what Shell is:

# ls-l ' which sh '

# to modify the following parameters as needed

Number of backup_count=10 # log scrolling

backup_size=$ ((1024 * 1024 * 200)) # Single log file size

BACKUP_INTERVAL=60 # detection interval, in seconds

# If the file specified by dirs_list exists, read the directory from dirs_list.

# Otherwise, only the single directory specified by Backup_dir is processed

# When you specify a file or add or subtract directory to dirs_list, you do not need to restart log_rotater.sh

Backup_dir=. # directory where log files are located

Dirs_list=./dirs.list # Stores directory listing files, requiring one row of directories

# process log scrolling under a single directory

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.