Created
January 30, 2024 07:17
-
-
Save JonasGao/68701ae68734e489bc208e6f7f384223 to your computer and use it in GitHub Desktop.
Rotate nginx log
This file contains 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 | |
cd /usr/local/nginx/logs | |
PID=$(cat nginx.pid) | |
DATE=$(date +%Y%m%d) | |
LOG="access.log" | |
FILE="$LOG.$DATE" | |
GZ="${FILE}.gz" | |
echo "Working in $(pwd), PID: $PID" | |
[ -f $GZ ] && echo "\"$GZ\" already exists, skip." && exit 1 | |
mv $LOG $FILE | |
echo "Moved to $FILE, will reload logging" | |
kill -USR1 `cat nginx.pid` | |
sleep 1 | |
echo "Gzip $FILE" | |
gzip $FILE | |
echo "Finish" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment