I'm trying to process logs while tailing them.
This command works:
kubectl logs "$pod" --tail=100 | egrep pattern | cut -d ' ' -f 1
But this command produces no output:
kubectl logs "$pod" --tail=100 -f | egrep pattern | cut -d ' ' -f 1
The difference between the two is -f
passed to the kubectl logs
in the second variant, which follows the the logs instead of exiting.
Strangely enough, this works:
kubectl logs "$pod" --tail=100 -f | egrep pattern
And this works:
kubectl logs "$pod" --tail=100 -f | cut -d ' ' -f 1
It's only when you add the second pipe that it stops working.
What is going on here? I'm guessing this is an output buffering issue, but I'm not sure how to address it.
egrep
support--line-buffered
command line option? Try it.--line-buffered
did work. Thanks a lot. Do you know what's going on?| xargs echo {}
doesn't work though?echo
, yourxargs
is waiting for as many arguments as the OS will be able to take, or for EOF. There is no EOF, so it's waiting.