質問

I have a bash script that runs iperf and outputs the average bandwdith ie 3.80 Mbits/sec. What i'd like to do is get this output as an average of the connection speed.

So if I have a 10Mbit connection i'd like to know what 3.80 Mbits/sec is of that so output something like

3.80 Mbits/sec 38%

I'm not sure how to do this.

My script does

iperf -c 1.1.1.1 >> /tmp/iperf.log
echo -e " \t $(awk '/Bandwidth/ {getline}; END{print $7, $8}' $iperflog"

which returns

 3.80 Mbits/sec

i'd like it to return

 3.80 Mbits/sec 38%
役に立ちましたか?

解決

Here an example with awk:

user@host:~# echo "3.80 Mbits/sec" | awk '{printf "%s %s%%\n", $0, $1/(10.0/100)}'
3.80 Mbits/sec 38%

To apply to your script just add the awk part after your command:

echo -e " \t $(awk '/Bandwidth/ {getline}; END{print $7, $8}' /tmp/iperf.log" | awk '{printf "%s %s%%\n", $0, $1/(10.0/100)}'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top