Skip to content

Instantly share code, notes, and snippets.

@jialechan
Last active October 10, 2017 09:47
Show Gist options
  • Save jialechan/ae96910add7a9a13c9e0d314071ba5a7 to your computer and use it in GitHub Desktop.
Save jialechan/ae96910add7a9a13c9e0d314071ba5a7 to your computer and use it in GitHub Desktop.
LogAnalytics配套的每天生成nginx日志脚本
#!/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