nginx 日志切割
#!/bin/bash#日志的位置,日志文件以access.log结尾Logs_Path=/home/wwwlogscd ${Logs_Path}#nginx的pid文件Pid_Path=/var/run/nginx.pid#日志切割后存放位置Logs_Logrotate=/home/wwwlogs#nginx 程序Nginx_Program=/usr/local/tengine/sbin/nginx#日志压缩的信息Compression_Days=3Compression_Path=/home/wwwlogs/$(date +"%Y%m")test -d ${Compression_Path} || mkdir -p ${Compression_Path} for log in $(ls *.access.log)do#切割日志mv $i ${Logs_Logrotate}/${log}.$(date +%F)#向nginx主进程发信号重新打开日志test -f ${Pid_Path} && kill -USR1 $(cat ${Pid_Path}) || ${Nginx_Program} #日志压缩 test -f ${log}.$(date -d "-${Compression_Days} days" +"%F") && mv ${log}.$(date -d "-${Compression_Days} days" +"%F") ${Compression_Path} if [ $? -eq 0 ]; then cd ${Compression_Path} /bin/gzip ${log}.$(date -d "-${Compression_Days} days" +"%F") cd - fidone