Last active
August 29, 2015 14:17
-
-
Save Maxwell2022/517da48484f201246fc6 to your computer and use it in GitHub Desktop.
Script to concatenate rotating logs for nginx and nodejs
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 | |
if [ $# -eq 0 ] | |
then | |
echo "Please specify the path of the logs in the first argument" | |
exit 0; | |
fi | |
ROOT=$1 | |
# Clean current directory | |
rm -Rf $ROOT/clean-logs | |
mkdir -p $ROOT/clean-logs/nginx | |
mkdir -p $ROOT/clean-logs/nodejs | |
cp -r $ROOT/nginx/*/*.gz $ROOT/clean-logs/nginx | |
cp -r $ROOT/nodejs/*/*.gz $ROOT/clean-logs/nodejs | |
# unzip archives in individual folders | |
echo "unzip log-rotate for nginx and nodejs..." | |
gunzip $ROOT/clean-logs/nginx/*.gz | |
gunzip $ROOT/clean-logs/nodejs/*.gz | |
# Concatenate all nginx logs files into one file | |
echo "Concatenate nginx log files..." | |
cat $ROOT/clean-logs/nginx/access.log* > $ROOT/clean-logs/nginx/access.log | |
cat $ROOT/clean-logs/nginx/error.log* > $ROOT/clean-logs/nginx/error.log | |
# Concatenate all nodejs logs files into one file | |
echo "Concatenate nodejs log files..." | |
cat $ROOT/clean-logs/nodejs/nodejs.log* > $ROOT/clean-logs/nodejs/nodejs.log | |
# Clean temporary folders | |
echo "Clean temporary folders..." | |
rm -f $ROOT/clean-logs/nginx/*.gz | |
rm -f $ROOT/clean-logs/nginx/access.log-* | |
rm -f $ROOT/clean-logs/nginx/error.log-* | |
rm -f $ROOT/clean-logs/nodejs/*.gz | |
rm -f $ROOT/clean-logs/nodejs/nodejs.log-* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment