trsgw 发表于 2015-5-7 08:59:44

nginx切割日志

#!/bin/bash
#
# Filename:    nginxCutLog.sh
# Author:      Qicheng

# 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


国安信仰 发表于 2015-6-26 13:29:25

不错,学习了!

yanglei90121 发表于 2015-7-15 14:11:15

妹子好刀法

chai931 发表于 2016-6-20 07:19:33

好的
页: [1]
查看完整版本: nginx切割日志