Skip to content

Instantly share code, notes, and snippets.

@Maxwell2022
Last active August 29, 2015 14:17
Show Gist options
  • Save Maxwell2022/517da48484f201246fc6 to your computer and use it in GitHub Desktop.
Save Maxwell2022/517da48484f201246fc6 to your computer and use it in GitHub Desktop.
Script to concatenate rotating logs for nginx and nodejs
#!/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