标签:shell
#!/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
标签:shell
原文地址:http://xjcf00.blog.51cto.com/10170403/1642566