nginx日志切割shell

#cat cutlog.sh

#!/bin/bash

logs_path=/usr/local/nginx/logs   log目录

yesterday=$(date -d "yesterday" +%Y-%m-%d)  定义日期
 
mv ${logs_path}/www_access.log ${logs_path}/www_access_${yesterday}.log
 
mv ${logs_path}/error.log ${logs_path}/error_${yesterday}.log
 
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)  重新打开日志文件
 
增加计划任务
#crontab -e 
0 0 * * *  bash /usr/local/nginx/logs/cutlog.sh
 
 
 

你可能感兴趣的:(nginx,nginx,log,职场,休闲)