Skip to content

Instantly share code, notes, and snippets.

@guileen
Created July 1, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guileen/8c88d9b71c273e63b87c to your computer and use it in GitHub Desktop.
Save guileen/8c88d9b71c273e63b87c to your computer and use it in GitHub Desktop.
rotate log
#!/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