I have a script to extract the logs of crushed pods, but i want also to give as a parameter the pod names (In case I need also the logs from other pods, not just crushed ones). My script looks like this:
#!/bin/bash
y=1;
for pod in "$@"
do
echo "Pod name: $y: $pod";
y=$((y + 1));
done
CrashLoopBackOff=`for i in $(kubectl get po -n namespace |grep CrashLoopBackOff | awk '{print $1}'); do echo $i; done`
echo "Pods in CrashLoopBackOff: "
echo
echo ======= $CrashLoopBackOff ==========
echo
arr2=()
while read -r CrashLoopBackOff _; do
while IFS= read -r line; do
arr2+=("$CrashLoopBackOff: $line")
done < <(kubectl logs "$CrashLoopBackOff" -n namespace| tail -10)
done < <(kubectl get po -n namespace| grep CrashLoopBackOff)
printf %s\\n "${arr2[@]}"
But seems that if I pass the pods name as arguments, the output is just for the crushed pod. I don't have so much experience with scripting and I got stuck here, any help is appreciated. Thank you
You can add this at the end of the file:
for pod in $@
do
echo "Printing logs for requested pod $pod"
kubectl logs -n namespace $pod | tail -n 10
done
Hope that helps to progress your script