Last active
October 28, 2016 19:10
-
-
Save dhrrgn/dc3f59780b64a604d2108a8a058c5810 to your computer and use it in GitHub Desktop.
Quick script to grab one or more log files (even gzipped ones) from multiple hosts at once.
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 | |
hosts=( | |
# list the hosts to grab the logs from | |
host1.foo.com | |
host2.foo.com | |
) | |
remote_files=( | |
# list the log files to grab | |
/var/log/nginx/error.log | |
/var/log/nginx/error.log-20161027.gz | |
) | |
log_directory=${PWD}/logs/$(date +'%Y-%m-%d-%H-%M-%S') | |
mkdir -p {$log_directory} | |
for host in ${hosts[@]}; do | |
mkdir -p $log_directory/$host | |
for file in ${remote_files[@]}; do | |
file=$(dirname $file)/$(basename $file .gz) | |
gz_file=$file.gz | |
ssh -t -o StrictHostKeyChecking=no $host "(sudo [ -f $gz_file ] && sudo gunzip $gz_file || true) && sudo cat $file 2>&1" >> $log_directory/$host/$(basename $file) | |
done | |
done | |
echo "Complete.\n\nLogs saved in: $log_directory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment