Last active
October 10, 2017 09:47
-
-
Save jialechan/ae96910add7a9a13c9e0d314071ba5a7 to your computer and use it in GitHub Desktop.
LogAnalytics配套的每天生成nginx日志脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script run at 00:00 | |
# 00 00 * * * log_daily.sh | |
# The Nginx logs path | |
LOG_PATH="/userdata1/nginx/logs" | |
PID_PATH="/userdata1/nginx/logs/nginx.pid" | |
for log in `ls $LOG_PATH`; do | |
echo $log | grep '.log$' > /dev/null | |
if [ $? -eq 0 ];then | |
NEW_LOG_FILE_PATH=$LOG_PATH/${log}_`date -d yesterday +%Y-%m-%d` | |
mv $LOG_PATH/$log $NEW_LOG_FILE_PATH | |
chmod 666 $NEW_LOG_FILE_PATH | |
fi | |
done | |
# ask nginx to generate new log file | |
kill -USR1 `cat $PID_PATH` | |
find $LOG_PATH -type f -mtime +3 -name "*access.log*" -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment