#!/bin/bash #日志的位置,日志文件以access.log结尾 Logs_Path=/home/wwwlogs cd ${Logs_Path} #nginx的pid文件 Pid_Path=/var/run/nginx.pid #日志切割后存放位置 Logs_Logrotate=/home/wwwlogs #nginx 程序 Nginx_Program=/usr/local/tengine/sbin/nginx #日志压缩的信息 Compression_Days=3 Compression_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 - fi done
时间: 2024-10-14 03:05:26