nginx日志按天截取

编写cut_nginx_log.sh脚本,脚本如下:

#!/bin/bash
logs_path=/app/lb/tengine-2.1.1/logs
yesterday=$(date -d “yesterday” +%Y-%m-%d)
mv ${logs_path}/access.log ${logs_path}/access_${yesterday}.log
mv ${logs_path}/error.log ${logs_path}/error_${yesterday}.log
kill -USR1 $(cat $logs_path/nginx.pid)

 

写好脚本之后,增加crontab定时任务,每天的00:00做日志切割

0 0 * * * /bin/bash /app/lb/tengine-2.1.1/cut_nginx_log.sh

发表评论

电子邮件地址不会被公开。 必填项已用*标注