[nginx]每天自动切割日志脚本

WBOY
Lepaskan: 2016-08-08 09:21:46
asal
1032 orang telah melayarinya

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>
Salin selepas log masuk

版权声明:本文为orangleliu(http://blog.csdn.net/orangleliu/)原创文章,文章转载请声明。

以上就介绍了[nginx]每天自动切割日志脚本,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan