日志切割-脚本
#!/bin/bash # This script run at 00:00 # The Nginx logs path logs_path="/data0/logs/nginx"#nginx存放日志路径 cd $logs_path#进入到nginx日志下面 mkdir -p ${logs_path}/$(date -d "yesterday" +"%Y%m")#创建日志日期目录 for logname in `ls *.log`#找到要切割的日志 do mv ${logs_path}/$logname ${logs_path}/$(date -d "yesterday" +"%Y%m")/$logname-$(date -d "yesterday" +"%Y%m%d")#把nginx下面的日志切割成日期形式放到日期目录下面 #kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` /usr/local/nginx/sbin/nginx -s reload done #00 00 * * * /bin/sh /usr/local/nginx/sbin/cut_nginx_log.sh >> /dev/null 2>&1