nginx日志定时自动切割shell脚本+crontab定时任务
vim cat_nginx_log.sh
#!/bin/bash
#nginx日志文件的存放路径
logs_path='/app/openresty/nginx/logs'
mv $logs_path/access.log $logs_path/access.$(date +%Y%m%d).log
mv $logs_path/error.log $logs_path/error.$(date +%Y%m%d).log
mv $logs_path/access.log $logs_path/longadmin.$(date +%Y%m%d).log
mv $logs_path/access.log $logs_path/dsyadmin.$(date +%Y%m%d).log
kill -USR1 `cat /app/openresty/nginx/logs/nginx.pid`
gzip $logs_path/access.$(date +%Y%m%d).log
gzip $logs_path/error.$(date +%Y%m%d).log
gzip $logs_path/longadmin.$(date +%Y%m%d).log
gzip $logs_path/dsyadmin.$(date +%Y%m%d).log
/usr/bin/find ${log_path} -type f -name "*.gz" -mtime +30 -exec rm -f {} \;
crontab 定时任务
0 0 * * * cat_nginx_log.sh