0

nethogs is a linux process bandwidth monitoring tool. https://github.com/raboof/nethogs

nethogs -t

it's output looks like this.

Refreshing:
sshd: root@pts/0/4002/0 0.185156        0.0773437
unknown TCP/0/0 0       0

Refreshing:
sshd: root@pts/0/4002/0 0.220703        0.0902344
unknown TCP/0/0 0       0

Refreshing:
sshd: root@pts/0/4002/0 0.217578        0.0902344
unknown TCP/0/0 0       0

I'm trying to to parse it's outout with awk.

nethogs -t | awk {'print $0}' 

returns no output :-(

nethogs -t | awk {'readline tmp; print tmp}' 

much the same ;

I presume it's the way nethogs is buffering it's output or some other quirky way it's writing it's output.

nethogs -t | awk -W interactive '{print $2}'

i get some output, but it's not working as expected.

I've tried playing with awk's RS and FS settings, but no luck.

The Unix Janitor
  • 2,458
  • 15
  • 13

2 Answers2

1

I tried to reproduce the issue, but I couldn't, at least, not in a terminal (in my case, awk printed the lines as expected), so this is a guess only.

You can try to avoid buffering by reading the output line by line from the shell like this:

while read line; do

    # Do some real processing here
    # instead of the echo
    echo "-> $line"

done < <(nethogs -t)
Lacek
  • 7,233
  • 24
  • 28
0

I'm not familiar with nethogs but I will check it out. One idea, try redirecting sterr to stdout like this.

nethogs -t 2>&1 | awk {'print $0}'
dmourati
  • 25,540
  • 2
  • 42
  • 72
  • thanks for the idea, but it just hangs. It must be something to do with 'how' it outputting the character stream.. maybe it's buffering or not flushing? interesting... – The Unix Janitor Jul 03 '20 at 01:37