Created
October 5, 2018 08:08
-
-
Save benzBrake/f98452ee8b0592fbfdde327a2dcdd473 to your computer and use it in GitHub Desktop.
split nginx log simplely
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/sh | |
| export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | |
| BASE_DIR="$1" | |
| DATE_FORMAT=`date +"%Y%m%d"` | |
| NGINX_DIR=nginx | |
| if [ -z "$BASE_DIR" ]; then | |
| echo "Base directory is not specified." | |
| exit 1 | |
| fi | |
| cd ${BASE_DIR} | |
| for log in `\ls *.log` | |
| do | |
| \mv ${log} ${log}.${DATE_FORMAT} | |
| done | |
| ${NGINX_DIR} -s reload |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.Save this script to /server/scripts/split_nginx_log.sh
2.Add cron job
00 00 * * * /bin/sh /server/scripts/split_nginx_log.sh NGINX_LOG_DIRECTORY >/dev/null 2>&1