This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Having output Log in tshark update by deleting the previous line.

0

I'm using tshark to capture RSSI values in an attempt at wifi triangulation.

I have it set up so that the log only outputs the RSSI value. The command I'm using is:

'tshark -I -i wlan2 -R "wlan.addr == 58:1f:aa:2a:80:1e && wlan.addr == Broadcast" -o column.format:'"RSSI", %e' > /tmp/log.txt'

I'm using python function readline() to grab the first line of the log file and assign the RSSI to a variable to be sent into a triangulation algorithm.

I'm wondering if there's a way to have the log update constantly re-writing the first line of the log file.

asked 04 Oct '13, 18:53

Evan%20Watler's gravatar image

Evan Watler
11113
accept rate: 0%

edited 04 Oct '13, 18:54


2 Answers:

0

I see a couple of options:

  • Use "tail -f /tmp/log.txt" within python to read from
  • Use "tshark -I -i wlan2 -R "wlan.addr == 58:1f:aa:2a:80:1e && wlan.addr == Broadcast" -o column.format:'"RSSI", %e'" within python to read from

If you really need to read from a file, then you can use some command line piping to overwrite the first line, something like:

tshark -r pcap/http.cap | awk '{print >"/tmp/log.txt";close "/tmp/log.txt"}'

answered 05 Oct '13, 01:44

SYN-bit's gravatar image

SYN-bit ♦♦
17.1k957245
accept rate: 20%

0

I'm wondering if there's a way to have the log update constantly re-writing the first line of the log file.

That's where named pipes can help. They work like a FIFO and thus you will always get the lines in the order they were written, one by one, just by calling readline() on them.

Here is how you can do it:

>mkfifo /tmp/tshark_pipe   
>tshark -I -i wlan2 -l -R "wlan.addr == 58:1f:aa:2a:80:1e && wlan.addr == Broadcast" -o column.format:'"RSSI", %e' >/tmp/tshark_pipe 2>/dev/null' &  
>python -u analyze.py

I added some options (-l and 2>/dev/null) to your tshark command. -l is necessary to disable buffered output, which tells tshark to flush the output buffer after every packet. The rest should be clear.

Here is the (very basic!) python code. Please extend it to your needs. Obviously you need to extract the RSSI values from the line in the python code and then feed that into your algorithm.

import os

tshark_pipe = "/tmp/tshark_pipe"

pipe = open(tshark_pipe, 'r')

while True: data=pipe.readline() if data: print "Data: " + data

pipe.close()

Regards
Kurt

answered 07 Oct ‘13, 13:40

Kurt%20Knochner's gravatar image

Kurt Knochner ♦
24.8k1039237
accept rate: 15%

edited 07 Oct ‘13, 13:41