首页 > 代码库 > Nginx日志分割脚本

Nginx日志分割脚本

1.Nginx日志分割脚本1:

#!/bin/sh

LOGS_PATH=/usr/local/nginx/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 /usr/local/nginx/var/run/nginx.pid`


2.Nginx日志分割脚本2:

#!/bin/sh

dateformat=`date +%Y%m%d`

basedir="/usr/local/nginx"

nginxlogdir="$basedir/logs"

logname="access"

[ -d $nginxlogdir ] && cd $nginxlogdir||exit 1

[ -f ${logname}.log ]||exit 1

/bin/mv ${logname}.log ${dateformat}_${logname}.log

$basedir/sbin/nginx -s reload


3.(使用以上脚本任意即可,只是日志格式不同)加入定时任务:

#crontab -l

59     23     *      *      *      /bin/bash /cut.sh >/dev/null 2>&1



本文出自 “花之旭的博客” 博客,请务必保留此出处http://huazhixu123.blog.51cto.com/1591874/1948487

Nginx日志分割脚本