I’m trying to build a script in Linux (Debian 10) that shows the net usage (%) of a process passed as an argument.
This is the code, but there isn’t any output:
ProcessName=$1
(nethogs -t ens33 | awk '/$ProcessName/{print $3}') &> output.txt
I’m trying to build a script in Linux (Debian 10) that shows the net usage (%) of a process passed as an argument.
This is the code, but there isn’t any output:
ProcessName=$1
(nethogs -t ens33 | awk '/$ProcessName/{print $3}') &> output.txt
2
Answers
What you’re doing wrong is single-quoting
$ProcessName
while wanting this to be parameter-expanded. To get the expansion, just don’t quote there, e. g.:While using tracemode
nethogs -t
, first field of output is program and it can consists of irregular number of arguments.In case of brave:
so
$3
will no longer be as expected, you need to get last column of output using$(NF)
as follow:for second last column: