您的位置:首页 > 运维架构 > Nginx

nginx切割日志

2015-05-06 15:21 246 查看
#!/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


本文出自 “湘江吹疯” 博客,请务必保留此出处http://xjcf00.blog.51cto.com/10170403/1642566
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: