Nginx日志切割脚本(一)

logs_path="/usr/local/nginx/logs/"
logfiles="access.log error.log"

server=`hostname`
date=$(date -d "yesterday" +"%Y%m%d")
save_path=${logs_path}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
mkdir -p ${save_path}

for log in ${logfiles};
do mv ${logs_path}/${log} ${save_path}/${log}.${date}.${server};
done

kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`

for log in ${logfiles};
do gzip ${save_path}/${log}.${date}.${server};
done

你可能感兴趣的:(nginx,脚本,Access)