Created
July 1, 2015 03:08
-
-
Save guileen/8c88d9b71c273e63b87c to your computer and use it in GitHub Desktop.
rotate log
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 | |
DIR=/data/logs/nginx/ | |
rotate_log() { | |
FILENAME=$1 | |
SRC=$DIR/$FILENAME | |
DEST=$DIR/${FILENAME}.$(date yesterday +%y%m%d) | |
mv $SRC $DEST | |
} | |
compress_log() { | |
FILENAME=$1 | |
SRC=$DIR/$FILENAME | |
DEST=$DIR/${FILENAME}.$(date yesterday +%y%m%d) | |
gzip $DEST | |
} | |
rotate_log access.log | |
rotate_log error.log | |
# rotate_log foo.log | |
kill -USR1 `cat /var/run/nginx.pid` | |
sleep 1 | |
# compress_log foo.log | |
compress_log access.log | |
compress_log error.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment