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