0

How do I save the live streaming output of this command to a variable/connection line-by-line running in a while loop? Something like:

netvalue <-system("tcpdump -A -i eth0 port 80 | grep foo")
while(T) {
...
nvar <- netvalue + othervalue
...
}

OR

In a terminal: 
$ tcpdump ... | grep --line-buffered [myterm] > fifofile

Then in R:
> con = fifo("fifofile", "r")
> open(con, "r")
> con
  description    class        mode        text      opened    can read
     "fifo"      "fifo"         "r"      "text"    "opened"       "yes"
  can write
    "no"    
> readLines(con, n = 1)
> [myterm]

.. but it only works sometimes, and often 
for a limited term, when it fails always returning:

> character(0)

Purging the entire fifofile with the "-1" argument in readLines(con, n = -1) seems to kill the connection consitently!?

  • possible duplicate of [Capture both exit status and output from a system call in R](http://stackoverflow.com/questions/7014081/capture-both-exit-status-and-output-from-a-system-call-in-r) –  Sep 15 '15 at 05:37

1 Answers1

0

tcpdump provide pcap file output with "-w filename" parameter.

you can use this method to store data in file and use alternative script with python or R to read line by line from it.

Neo...
  • 96
  • 3
  • So wouldn't be possible to store it to a connection, then open/ref/close the conn thereafter? – Scipio The Elder Sep 15 '15 at 11:44
  • If I ran it to a fifo like: tcpdump... grep --line-buffered > namedpipe, then read the top line of the pipe, would that work? – Scipio The Elder Sep 15 '15 at 12:12
  • no tcpdump output is not like normal stdout and u can't normally pipe it into file, i don't test this method but maybe you can store like this: tcpdump > result.txt 2>&1, however i did not test. test it and tell me ;) – Neo... Sep 15 '15 at 17:47