: This article mainly introduces the [nginx] Daily automatic log cutting script. if you are interested in the PHP Tutorial, please refer to it.
When the daily log volume of nginx is large, it is best to automatically cut and store the logs every day, which can be used for future query and analysis.
#!/bin/sh####################filename: nginx_log_rotate.sh#vsersion: 0.1v#1 0 * * * /bin/sh /home/project/monitor/nginx_log_rotate.sh >/dev/null 2>&1###################logs_path="/usr/local/openresty/nginx/logs"old_logs_path=${logs_path}/oldnginx_pid=`cat /usr/local/openresty/nginx/logs/nginx.pid`time_stamp=`date -d"yesterday" +"%Y-%m-%d"`mkdir -p ${old_logs_path}#grep some mode filefor file in `ls $logs_path | grep log$ | grep -v '^20'`doif [ ! -f${old_logs_path}/${time_stamp}_$file ] then dst_file="${old_logs_path}/${time_stamp}_$file"else dst_file="${old_logs_path}/${time_stamp}_$file.$$"fi mv $logs_path/$file$dst_file#gzip -f $dst_file # do something with access.log.0donekill -USR1 $nginx_pid
Copyright: This article is orangleliu (http://blog.csdn.net/orangleliu/) original article, reprinted please declare.
The above introduces the [nginx] Daily automatic log cutting script, including the content, hope to be helpful to friends who are interested in PHP tutorials.