Harry
Harry
发布于 2021-03-09 / 810 阅读
0
0

Nginx 日志切分脚本

#!/bin/sh
year=`date +%Y`
month=`date +%m`
day=`date +%d`
# 日志存储路径
logs_backup_path="/data/software/nginx/logs/$year$month"
# 日志存放文件夹
logs_path="/data/software/nginx/logs/"
logs_access="access"
logs_error="error"
# Nginx pid文件路径
pid="/var/run/nginx.pid"

[ -d $logs_backup_path ]||mkdir -p $logs_backup_path
rq=`date +%Y%m%d`
mv ${logs_path}${logs_access}.log ${logs_backup_path}/${logs_access}_${rq}.log
mv ${logs_path}${logs_error}.log ${logs_backup_path}/${logs_error}_${rq}.log
kill -USR1 $(cat ${pid})

最后把脚本添加可执行权限

chmod a+x 脚本文件名

评论