Created
June 17, 2020 22:22
-
-
Save ps-przemekaugustyn/a9136f0c8114b94867acfddce718a2e7 to your computer and use it in GitHub Desktop.
Filter container logs and output to file
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
#!/bin/bash | |
label=$1 | |
namespace=$2 | |
filter=$3 | |
fileout=$4 | |
container=$5 | |
if [ $# -eq 0 ] | |
then | |
echo "no arguments supplied, [label] [namespace] [filter] [filename.output] [container]" | |
echo "example: app=updatedb spuprod ds2 test.txt" | |
exit 1 | |
fi | |
while IFS= read -r pod | |
do | |
echo processing logs of $pod | |
kubectl logs -n spuprod -c $container $pod|grep -B 5 fail|grep sellerId>> $fileout | |
done < <(kubectl get pods --no-headers=true -o custom-columns=:metadata.name -n $namespace -l $label |grep $filter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be further post-processed (e.g. for grouping) with
awk '{a[$8]+=1;}END{for(i in a)print i", "a[i];}' test.txt