nginx每天日誌量比較大的時候,最好每天自動切割,存儲,這樣可以方面以後的查詢和分析
<code><span>#!/bin/sh</span><span>###################</span><span>#filename: nginx_log_rotate.sh</span><span>#vsersion: 0.1v</span><span>#1 0 * * * /bin/sh /home/project/monitor/nginx_log_rotate.sh >/dev/null 2>&1</span><span>###################</span>logs_path=<span>"/usr/local/openresty/nginx/logs"</span> old_logs_path=<span>${logs_path}</span>/old nginx_pid=`cat /usr/local/openresty/nginx/logs/nginx.pid` time_stamp=`date <span>-d</span><span>"yesterday"</span> +<span>"%Y-%m-%d"</span>` mkdir -p <span>${old_logs_path}</span><span>#grep some mode file</span><span>for</span> file <span>in</span> `ls <span>$logs_path</span> | grep log$ | grep -v <span>'^20'</span>` <span>do</span><span>if</span> [ ! <span>-f</span><span>${old_logs_path}</span>/<span>${time_stamp}</span>_<span>$file</span> ] <span>then</span> dst_file=<span>"<span>${old_logs_path}</span>/<span>${time_stamp}</span>_<span>$file</span>"</span><span>else</span> dst_file=<span>"<span>${old_logs_path}</span>/<span>${time_stamp}</span>_<span>$file</span>.$$"</span><span>fi</span> mv <span>$logs_path</span>/<span>$file</span><span>$dst_file</span><span>#gzip -f $dst_file # do something with access.log.0</span><span>done</span>kill -USR1 <span>$nginx_pid</span></code>
版權聲明:本文為orangleliu(http://blog.csdn.net /orangleliu/)原創文章,文章轉載請聲明。
以上就介紹了[nginx]每天自動切割日誌腳本,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。