Skip to content

Instantly share code, notes, and snippets.

@ps-przemekaugustyn
Created June 17, 2020 22:22
Show Gist options
  • Save ps-przemekaugustyn/a9136f0c8114b94867acfddce718a2e7 to your computer and use it in GitHub Desktop.
Save ps-przemekaugustyn/a9136f0c8114b94867acfddce718a2e7 to your computer and use it in GitHub Desktop.
Filter container logs and output to file
#!/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)
@ps-przemekaugustyn
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment