nginx切割日誌

#!/bin/bash
#
# Filename:    nginxCutLog.sh
# Author:      Qicheng
# Website:     http://qicheng0211.blog.51cto.com/
# Description: 切割nginx日誌
# Notes:       設置crontab,每天23點59分定時執行
#
ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ];then
    echo "Error: 必須以root用戶運行此程序!"
    exit 1
fi
 
nginx_logs_dir="/data/log/nginx"
nginx_pid_file="/var/run/nginx.pid"
# 切割後的日誌文件名,例如54_access_20141022.log
nginx_log_today="$nginx_logs_dir/54_access_`date +%Y%m%d`.log"
[ -f "$nginx_log_today" ] && exit 1
mv $nginx_logs_dir/54_access.log $nginx_log_today
# 給nginx發送USR1信號,使重新打開新的access.log日誌文件
[ -f $nginx_pid_file ] && /bin/kill -USR1 $(cat $nginx_pid_file)
chown www:www /data/log/nginx -R
chmod 755 /data/log/nginx/*
/usr/local/nginx/sbin/nginx -s reload


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章