每天凌晨运行切割日志的shell脚本
10 00* * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
脚本如下
#!/bin/bash
# #This script run at 00:10
## 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 ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/nginx.pid`
时间: 2024-09-30 12:20:03