Skip to content

Instantly share code, notes, and snippets.

@joergeschmann
Created August 6, 2016 08:25
Show Gist options
  • Save joergeschmann/a1b03b3db35b86d59de50bd18ad8640e to your computer and use it in GitHub Desktop.
Save joergeschmann/a1b03b3db35b86d59de50bd18ad8640e to your computer and use it in GitHub Desktop.
Copy distributed log files into a folder
baseFolder="/tmp/app"
logFilesToCopy=("$baseFolder/auth/log/auth.log" "$baseFolder/jobs/log/jobs.log" "$baseFolder/app.log")
destination="/tmp/logs"
for logFile in ${logFilesToCopy[@]}
do
# logFile -> variable; ## -> greedy front trim; */ -> match everything until the last '/'
filename=${logFile##*/}
currentFile="$destination/$filename"
if [ -f "$currentFile" ]
then
rm "$currentFile"
fi
cp -f "$logFile" "$destination"
chmod 644 "$currentFile"
done
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment