-
Notifications
You must be signed in to change notification settings - Fork 1
/
getContainerLogs.sh
executable file
·46 lines (39 loc) · 1.42 KB
/
getContainerLogs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
function getLogs(){
## If no containers running return
CONTAINERS=$(docker ps -a | wc -l)
if test $CONTAINERS -eq 1
then
echo "============= No Docker Containers running =========="
return
fi
printf "=========================================================\n"
printf " START CAPTURE ALL DOCKER CONTAINER LOGS \n"
printf "=========================================================\n"
DATE=`date +%Y_%m_%d_%H_%M_%S`
TAR_FILE="$DATE-logs.tar.gz"
for (( i=0; i<3; i=$i+1))
do
docker logs zookeeper$i >& zookeeper$i.txt
docker logs kafka$i >& kafka$i.txt
docker logs orderer$i.example.com >& orderer$i.txt
docker logs couchdb$i &> couchdb$i.txt
done
docker logs couchdb3 &> couchdb3.txt
docker logs peer0.org1.example.com &> peer0_org1.txt
docker logs peer1.org1.example.com &> peer1_org1.txt
docker logs peer0.org2.example.com &> peer0_org2.txt
docker logs peer1.org2.example.com &> peer1_org2.txt
docker logs peer0.org1.cli &> peer0_org1_cli.txt
docker logs peer0.org2.cli &> peer0_org2_cli.txt
docker logs peer1.org1.cli &> peer1_org1_cli.txt
docker logs peer1.org2.cli &> peer1_org2_cli.txt
## tar the logs
tar czf $TAR_FILE *.txt
## cleanup
rm -rf *.txt
printf "=========================================================\n"
printf " CAPTURED DOCKER CONTAINER LOGS TO $TAR_FILE \n"
printf "=========================================================\n"
}
getLogs