当前位置: 代码迷 >> Web前端 >> nginx 日记每日轮询脚本
  详细解决方案

nginx 日记每日轮询脚本

热度:119   发布时间:2012-11-25 11:44:31.0
nginx 日志每日轮询脚本
#!/bin/bash
# This script run at 00:00
# 00 00 * *  * log_daily.sh

# The Nginx logs path
LOG_PATH="/usr/local/nginx/logs"

for log in `ls $LOG_PATH`; do
    echo $log | grep '.log$' > /dev/null
    if [ $? -eq 0 ];then
        NEW_LOG_FILE_PATH=$LOG_PATH/${log}_`date -d yesterday +%Y_%m_%d`
        mv $LOG_PATH/$log $NEW_LOG_FILE_PATH
        chmod 666 $NEW_LOG_FILE_PATH
    fi
done

# ask nginx to generate new log file
kill -USR1 `cat /usr/local/nginx/var/nginx.pid`
?

?