Nginx log splitting script and nginx log splitting script
#! /Bin/bash
#01 00 ***/nginxlogs/ngx_logcut.sh>/dev/null 2> & 1 # the script can be automatically executed in a scheduled task.
Pidfile =/var/run/nginx. pid # nginx process pid File
Logpath = '/nginxlogs/' # log directory
Keepdays = 30 # Log Retention days
Logfiles = (error. log access. log) # list log names in Arrays
Cd $ logpath # enter the log directory
For logfile in $ {logfiles [@]}; do # Matches in array form
If [! -E $ logfile];
Then
Continue
Fi
Find.-type f-name $ logfile "20 *"-mtime + $ keepdays-exec rm {}\; # find the matching log and delete it
Mv $ logfile $ (date-d "yesterday" + "% Y % m % d") # change yesterday's log to log name + date Format
Done
Kill-USR1 'cat $ pidfile' # USR1 is usually used to inform the application to reload the configuration file. For example, if the nginx server sends a USR1 signal, the following steps will occur: stop accepting new connections, wait for the current connection to stop, re-load the configuration file, re-open the log file, restart the server, so as to achieve relatively smooth changes without shutting down