nginx 日志文件切割
shell 脚本
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/longadmin.log $logs_path/longadmin.$(date +%Y%m%d).log mv $logs_path/dsyadmin.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 定时任务
[appdeploy@hwnavla7109zzzz nginx]$ crontab -l #每天凌晨0点,nginx日志,自动切割定时任务 0 0 * * * /app/openresty/nginx/logs/cat_nginx_log.sh