小美Nginx日志切割及推送脚本

#!/bin/bash
#

##nginx日志收集##

##定义目录##
LOGS_PATH=/mnt/app/nginx/logs/

##定义TIME##
YESTERDAY=$(date -d last-day +%Y%m%d)

##日志切割##
mkdir /tmp/log.${YESTERDAY}
mv ${LOGS_PATH}/yimei.app.access.log /tmp/log.${YESTERDAY}/yimei.app.access.${YESTERDAY}.log
mv ${LOGS_PATH}/yimei.cd.app.access.log /tmp/log.${YESTERDAY}/yimei.cd.app.access.${YESTERDAY}.log
mv ${LOGS_PATH}/yimei.sh.app.access.log /tmp/log.${YESTERDAY}/yimei.sh.app.access.${YESTERDAY}.log
mv ${LOGS_PATH}/yimei.sz.app.access.log /tmp/log.${YESTERDAY}/yimei.sz.app.access.${YESTERDAY}.log
mv ${LOGS_PATH}/yimei.wh.app.access.log /tmp/log.${YESTERDAY}/yimei.wh.app.access.${YESTERDAY}.log
#mv ${LOGS_PATH}/yimei.gz.app.access.log /tmp/log.${LOGS_PATH}/yimei.gz.app.access.${YESTERDAY}.log

##重新生成新的日志##
kill -USR1 $(cat /usr/local/app/nginx/logs/nginx.pid)

##将日志推送至数据中心##
##PATH:/mnt/log/daodao_task_02/nginx
rsync -avzt –progress –password-file=/etc/rsyncd/rsyncd.pass /tmp/log.${YESTERDAY}/ admin@10.172.170.89::daodao_third_02/nginx/ >>/etc/rsyncd/log/error_rsync_nginx.log
if [ $? = 0 ]; then
echo “${YESTERDAY} Rsync nginx_log success”>>/etc/rsyncd/log/error_rsync_nginx.log
rm -fr /tmp/log.${YESTERDAY}
else
echo “Rsync error”>>/etc/rsyncd/log/error_rsync_nginx.log
exit
fi

发表评论

邮箱地址不会被公开。