Fix stats display in test_monitor_tshark.sh
- Filter out 'X packets captured' summary lines from packet count - Only count lines with tab-separated fields (actual packet data) - Add sync to force output flush - Ensure stats always display immediately after capture - Remove trap that was interfering with normal flow Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
fb7dca0137
commit
8576960251
|
|
@ -119,7 +119,7 @@ echo ""
|
||||||
# Capture for specified duration and count packets
|
# Capture for specified duration and count packets
|
||||||
echo "Capturing packets for $DURATION seconds..."
|
echo "Capturing packets for $DURATION seconds..."
|
||||||
|
|
||||||
# Run capture in background and show progress
|
# Run capture with timeout
|
||||||
CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
||||||
-e frame.number \
|
-e frame.number \
|
||||||
-e frame.time \
|
-e frame.time \
|
||||||
|
|
@ -132,25 +132,30 @@ CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
||||||
2>&1)
|
2>&1)
|
||||||
CAPTURE_EXIT_CODE=$?
|
CAPTURE_EXIT_CODE=$?
|
||||||
|
|
||||||
# Immediately show stats after capture completes
|
# Force output flush
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Show stats immediately after capture completes
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Capture Statistics ==="
|
echo "=== Capture Statistics ==="
|
||||||
|
|
||||||
# Show any warnings/errors
|
# Show any warnings/errors (but not the "Running as root" or "Capturing" messages)
|
||||||
WARNINGS=$(echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | head -5 || true)
|
WARNINGS=$(echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | grep -v -E "(Running as|Capturing)" | head -5 || true)
|
||||||
if [ -n "$WARNINGS" ]; then
|
if [ -n "$WARNINGS" ]; then
|
||||||
echo "$WARNINGS"
|
echo "$WARNINGS"
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Count total packets captured (lines starting with a number)
|
# Count total packets captured (lines starting with a number followed by tab)
|
||||||
PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' || true)
|
# Filter out lines like "100 packets captured" which don't have tabs
|
||||||
|
PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+\t' || true)
|
||||||
FINAL_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0")
|
FINAL_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0")
|
||||||
|
|
||||||
# Count packets with PLCP headers (radiotap present)
|
# Count packets with PLCP headers (radiotap present)
|
||||||
# radiotap.present field is the 8th field (after frame.number, frame.time, wlan.sa, wlan.da, wlan.fc.type, wlan.fc.subtype, wlan.fc.type_subtype)
|
# radiotap.present field is the 8th field (after frame.number, frame.time, wlan.sa, wlan.da, wlan.fc.type, wlan.fc.subtype, wlan.fc.type_subtype)
|
||||||
PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 8 && $1 != "" && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0")
|
PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 8 && $1 != "" && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0")
|
||||||
|
|
||||||
# Display stats immediately
|
# Display stats immediately - always show these
|
||||||
echo "Total packets captured: $FINAL_COUNT"
|
echo "Total packets captured: $FINAL_COUNT"
|
||||||
echo "PLCP headers: $PLCP_COUNT"
|
echo "PLCP headers: $PLCP_COUNT"
|
||||||
if [ "$FINAL_COUNT" -gt 0 ]; then
|
if [ "$FINAL_COUNT" -gt 0 ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue