#!/bin/bash## filename: nginxcutlog.sh# author: qicheng# website: http://qicheng0211.blog.51cto.com/# description : cut nginx Log # notes: settings crontab, daily 23:59 scheduled execution #root_uid=0if [ "$UID" -ne "$ROOT _uid" ];then echo "error: This program must be run as root user! " exit 1fi nginx_logs_dir="/data/log/nginx "nginx_pid_file="/var/run/nginx.pid "# the log file name after the cut, such as 54_access_20141022.lognginx_log_today=" $nginx _logs_dir/54_access_ ' date +%y%m%d '. Log "[ -f "$nginx _log_today" ] && exit 1mv $nginx _logs_dir/54_access.log $nginx _log_today# send USR1 signal to Nginx to reopen the new Access.log log file [ -f $nginx _pid_file ] && /bin/kill -usr1 $ (cat $nginx _pid_file) Chown www:www /data/log/nginx -rchMod 755 /data/log/nginx/*/usr/local/nginx/sbin/nginx -s reload
This article is from the "Xiangjiang River Blowing Crazy" blog, please make sure to keep this source http://xjcf00.blog.51cto.com/10170403/1642566
Nginx Cutting Log