Skip to content

编写每天定时切割nginx日志的脚本

[shell] [/shell]
1、编写脚本
#!/bin/bash
#this script run at 00:00
#the nginx logs path
logs_path="/usr/local/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" + "%Y“)/$(date -d ”yesterday" + "%m")/
mv ${logs_path} access.log ${log_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 'cat /usr/local/nginx/conf/nginx.pid'
2、设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

00 00 * * * /bin/bash /usr/local/nginx/conf/cut_nginx_log.sh