0

I tried to make iftop execute for 80000 seconds and output to a file:

sudo iftop -i wlan0 -s 80000 -t > "$file"

However all I can find in the file is

Listening on wlan0

without the actual output. When I remove the -s 80000, then it works fine.

Why is there no actual output in the file?

Adam
  • 1

1 Answers1

0

iftop -h says -s num prints one single text output after num seconds, then quits.

If you check the file when iftop is still collecting data, the result will not yet be there. With -s 80000 the tool should exit after 22+ hours. Read the file then.


To capture more than one chunk of output:

  • Run iftop -t -s … several times in a loop. Note there's overhead: -s 1 can take 2 seconds or so; therefore the number of loops does not simply translate to total time in this case. And total statistics ("cumulative" etc.) will be independent in each loop, so this is not the best approach. You would want to append (>>) each time or redirect the output from the entire loop.

  • Use timeout. Example:

     sudo timeout -s INT --foreground 20 iftop -i wlan0 -t
    

    timeout --foreground … sudo … seems safer but it will most likely not work because children of sudo will not be timed out.

  • Run iftop -t … > … in the background, sleep as long as you wish and finally kill iftop.

    Not working because iftop wants to use the terminal anyway. A cumbersome workaround is to run iftop in the foreground, then sleep and kill in another terminal.