The core of this script is: compress the log file every morning and move it to the Directory of the corresponding year and month, then regenerate the log file, and record the log #! /Bin/bashlogs_path & quot;/home/wwwlog/& quot; # log storage location year 'date + % Y' # year month 'Dat...
The core of the following script is:
Compress the log file every morning and move it to the corresponding year/month Directory. then, regenerate the log file and record the log.
#! /Bin/bash
Logs_path = "/home/wwwlog/" # log storage location
Year = 'date + % Y' # year
Month = 'date + % M' # month
Day = 'date + % Y % m % d' # date
Time = 'date + % Y % m % d-% H: % M: % s' # time
Weblog = "www.pcstars.com _ access" # web access log
CutNginxLog = "/home/sysadmin/zhaoyj/CutNginx. Log" # Split nginx Log records
If [$ day-eq 1]; then # determines if it is the first day of the month. if the condition is true, create the directory/home/wwwlog/year/month.
Mkdir-p $ {logs_path} $ year/$ month/
Fi
Cd $ logs_path # enter the current directory
Tar jcf access_day.log.tar.bz2 access. log # compress the log file
Echo-n> access. log # clear the file and record the log
DuAccess = 'Du-sh access_day.log.tar.bz2 | awk '{print $1} ''# count the tar size to record logs.
Mv access_1_day.log.tar.bz2 $ {logs_path} $ year/$ month/# Move the log file to the corresponding directory
Echo "access_$day.log.tar.bz2: $ DuAccess $ time" >>$ CutNginxLog # Record logs
Tar jcf ${weblog1__day.tar.bz2 $ weblog. log
Echo-n> $ weblog. log
DuPcstars = 'Du-sh zookeeper weblog=_day.tar.bz2 | awk '{print $1 }''
Mv invalid weblog1__day.tar.bz2 $ {logs_path} $ year/$ month/
Echo "commandid weblog1__day.tar.bz2: $ DuPcstars $ time" >>$ CutNginxLog
DuPcstars = 'Du-sh zookeeper weblog=_day.tar.bz2 | awk '{print $1 }''
Mv invalid weblog1__day.tar.bz2 $ {logs_path} $ year/$ month/
Echo "commandid weblog1__day.tar.bz2: $ DuPcstars $ time" >>$ CutNginxLog
Echo ""> $ CutNginxLog
Echo ""> $ CutNginxLog
Author's "ANLJF column"