I'm running tshark on a fifo, and the following is a bare example of a loop that prints the output of tshark as it comes:
tshark -i $fifo | while read line; do
echo $line
done
The problem appears when I add filters to tshark. This example prints all $line
s only after tshark exits (IP address is hidden):
tshark -i $fifo -T fields -e text -R '
ip.src == **.**.***.** &&
http.response.code == 200 &&
http.content_encoding == "gzip" &&
http.content_type contains "text/html"
' | while read line; do
echo $line
done
I have tried in other forms with no luck:
while read line; do
echo $line
done < <(tshark ...)
while read line; do
echo $line
done <<<"$(tshark ...)"
Even grep prints the lines only after tshark ends:
tshark ... | grep .
I have tried running tshark without a pipe and the lines are printed correctly as they come. Why is the command after the pipe being feeded only after tshark exits?
Additional details: | tee
works, but I get everything printed again when tshark exits, so it is not a good deal.
strace
is your friend. What about cat (instead of tee)? And why is the output printed twice? – Hauke Laging Apr 14 '13 at 23:54unbuffer tshark
worked! I read the man page for unbuffer, but I couldn't really understand the reasoning behind this... see: http://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe – admirabilis Apr 15 '13 at 00:22