nginx日志切割

1.脚本实现

#!/bin/bash
LOGS_PATH=/usr/local/nginx/logs/
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
BACKUP_DIR=${LOGS_PATH}/logbakup/$YESTERDAY/
mkdir  -p $BACKUP_DIR
mv ${LOGS_PATH}/*.log $BACKUP_DIR
kill -USR1 `ps axu | grep "nginx: master process" | grep -v grep | awk '{print $2}'`
cd ${LOGS_PATH}/logbakup
tar -zcvf $YESTERDAY.tar.gz $YESTERDAY
rm -rf $YESTERDAY
exit 0
posted @ 2020-12-31 11:20  李家琦  阅读(57)  评论(0编辑  收藏  举报