<code><span>#!/bin/bash</span><span>## 零点执行该脚本</span><span>## Nginx 日志文件所在的目录</span> LOGS_PATH=/usr/local/nginx/logs <span>## 获取昨天的 yyyy-MM-dd</span> YESTERDAY=$(date <span>-d</span><span>"yesterday"</span> +%Y-%m-%d) <span>## 移动文件</span> mv <span>${LOGS_PATH}</span>/access_log <span>${LOGS_PATH}</span>/access_log.<span>${YESTERDAY}</span> mv <span>${LOGS_PATH}</span>/error.log <span>${LOGS_PATH}</span>/error.log.<span>${YESTERDAY}</span><span>## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件</span> kill -USR1 $(cat /usr/local/nginx/sbin/nginx.pid)</code>
放在Nginx 安装目录的 sbin 中,取名为 cut-log.sh
<code><span>#crantab</span><span>0</span><span>0</span> * * * /bin/bash /usr/<span>local</span>/nginx/sbin/cut-<span>log</span>.sh</code>
以上就介绍了Nginx日志切割脚本,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。