Created
August 22, 2019 16:16
-
-
Save pimentelra/b3473c3e8dcecba35ccfe5664e35f59b to your computer and use it in GitHub Desktop.
Bash script to compress and rotate nginx logs
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
#!/usr/bin/env bash | |
log_name='log_prefix' | |
for f in /var/log/nginx/${log_name}*.log; do | |
pattern="(.*)($log_name)(.*)" | |
[[ "$f" =~ $pattern ]] | |
/bin/gzip ${f} && /bin/kill -USR1 $(cat /run/nginx.pid) && /bin/mv ${f}.gz /var/log/nginx/$(date +%F-%T)${BASH_REMATCH[3]}.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment