标签:ext log 切割 day logs yesterday bash 开启 mkdir
log.sh 文件
#!/bin/bash
pid_path=/usr/local/nginx/logs/nginx.pid
basePath=/ext3/www/logs/
logPathDir=${basePath}$(date +"%Y%m")
mkdir -p ${logPathDir}
mv ${basePath}access.log ${logPathDir}/access_$(date -d "yesterday" +"%Y%m%d").log
mv ${basePath}error.log ${logPathDir}/error_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat ${pid_path}`
将log.sh 设置为可执行文件
crontab -e #开启定时执行 log.sh ,加入
30 0 * * * /usr/bin/bash /ext3/www/logs/log.sh
在logs文件夹下,以年月日分包的日志
标签:ext log 切割 day logs yesterday bash 开启 mkdir
原文地址:https://www.cnblogs.com/zhanglw456/p/13280477.html