Created
May 18, 2017 17:53
-
-
Save aaronzirbes/be0718de434a3d6c18a515c58140d1f5 to your computer and use it in GitHub Desktop.
Tails multiple k8s pods
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 | |
default_filter="(event.*|container-container.*|dci-osn-bridge.*)" | |
filter="${1}" | |
color=32 | |
if [ "$filter" == "" ]; then | |
filter="${default_filter}" | |
fi | |
function getPods() { | |
kubectl get pod \ | |
|cut -f 1 -d ' ' \ | |
|grep -v 'NAME' \ | |
|grep -E "${filter}" | |
} | |
function tailPod() { | |
pod="${1}" | |
kubectl logs -f $pod | sed -e "s/^/${pod}: /" |grep -E "^${pod}" | |
} | |
function tailEm() { | |
pods="${1}" | |
for pod in $pods; do | |
echo "tailing ${pod}" | |
tailPod $pod & | |
done | |
} | |
function waitForEm() { | |
for job in `jobs -p`; do | |
wait $job || let "FAIL+=1" | |
done | |
} | |
podlist=`getPods filter` | |
echo "pods: ${podlist}" | |
tailEm "$podlist" | |
waitForEm | |
pkill kubectl | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment