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