Created
February 8, 2019 22:51
-
-
Save ryanarlan0622/3039a26360351b95ef6c8b7a5396917c to your computer and use it in GitHub Desktop.
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 | |
set -eu | |
output_dir="container-logs" | |
timestamp=$(date +%s) | |
generate_logs() { | |
container_ids=($(docker ps | awk '{if (NR!=1)print $1}')) | |
container_names=($(docker ps | awk '{if (NR!=1)print $NF}')) | |
if [[ $container_ids ]]; then | |
for i in "${!container_ids[@]}"; do | |
# echo "${container_ids[i]}" "${container_names[i]}" | |
docker logs ${container_ids[i]} > $output_dir/${container_names[i]}.log | |
done | |
else | |
echo "No containers running" | |
fi | |
} | |
mkdir -p $output_dir | |
generate_logs | |
tar czf container-logs-$timestamp.tar.gz $output_dir | |
rm -rf $output_dir | |
echo "Log bundle container-logs-$timestamp.tar.gz has been successfully created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment