We renamed yesterday's log 00:00:01 every day, placed it in a specific directory, and then USR1 the information number control Nginx to regenerate a new log file
Create a new shell script under directory/usr/local/nginx/logs/runlog.sh
Note: The file location in the following code can be changed by itself
# define the SH interpreter
#!/bin/bush
# defines the storage location of the log to be split
Logpath=/usr/local/nginx/logs/access.log
# defines the storage location of the split log, $ ( Date-d yesterday +%y%m): directory named year + month
basepath=/usr/local/nginx/logs/$ (date-d yesterday +%y%m)
# Recursively creates a basepath-named directory
mkdir-p $BASHPATH
# to String ... Assign value to bak
bak= $BASEPATH/$ (date-d yesterday +%d) _access_log
# will rename $logpath to $bak
mv $LOGPATH $bak
# Create $ LOGPATH file Touch
$LOGPATH
# control nginx rebuild log file
kill-usr1 '/usr/local/nginx/logs/nginx.pid '
Then use the crontab command to edit the timed task
Crontab-e
Enter in the Open edit window
* * * * sh/usr/local/nginx/logs/runlog.sh
The meaning of the crontab file:
# in the crontab file that the user has created, each row represents a task, each field of each row represents a setting, its format is divided into six fields, the first five paragraphs is a time set segment, the sixth paragraph is the command segment to execute, the format is as follows:
# minute hour day month week
Command # Time
of the week and the moon the interpretation of each setting
minute represents the minute, which can be any integer from 0 to 59.
hour represents an hour, which can be any integer from 0 to 23.
Day represents a date, which can be any integer from 1 to 31.
Month represents the month, which can be any integer from 1 to 12. Week represents the day of the
week, which can be any integer from 0 to 7, where 0 or 7 represent Sunday.
command you want to execute, either a system command or a script file that you write yourself.
At this time, that is, set up the nginx of timed log cutting storage, every day 00:00:01 yesterday's log cut storage.