You are not logged in.
I found this script on the linuxquestions site that tests and displays network bandwidth. There's an error in the script though and my awk experience isn't enough to debug it and is giving me the error:
awk: cmd. line:10: printf ("%4.0f", Ratio)}
awk: cmd. line:10: ^ syntax error
awk: cmd. line:10: printf ("%4.0f", Ratio)}
awk: cmd. line:10: ^ syntax error
^C/home/todd/.bin/bandwidth-test: line 21: [: : integer expression expected
BW Surchargé - Moyenne de de Kb/sec pendant 20 secondes
This is the script:
#!/bin/bash
# bandwidth-test - test bandwidth from the command line
Fic_Tmp="/tmp/Fic_Tmp_VerifRatio.tmp"
NbrSec=20
/usr/bin/bwm-ng -I eth0 -o csv -T avg -C " " -c ${NbrSec} | awk '
BEGIN{
BytesS=0
NbrLecture=0}
/eth0/&&NR>2{
BytesS+=$5/1024
NbrLecture+=1}
END{
Ratio=BytesS/NbrLecture
}
printf ("%4.0f", Ratio)}' > ${Fic_Tmp}
Ratio=$(cat ${Fic_Tmp})
rm ${Fic_Tmp}
if [ "${Ratio}" -lt 110 ];then
echo "BW OK - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
exit 0
else
echo "BW Surchargé - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
exit 2
fi
exit $?
Anyone available to fix this for me?
Last edited by Gen2ly (2009-11-17 17:52:14)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
I didn't check if it works but the printf line should be within the braces of the END statement (so baseically there is an extra curly bracket):
END{
Ratio=BytesS/NbrLecture
printf ("%4.0f", Ratio)}' > ${Fic_Tmp}
Offline
Ah, thought I counted all those. Whoops . Yep that did the trick. Thanks benob.
Edit: Just FYI to any that read this. This script only checks if you are in the cap range, so it's not really a bandwidth tester for the command line. The nearest I've found is 'iperf' which I'm unable to get to use yet.
Edit2 : netperf seems better suited for this, only been able to learn how to do download speed test so far:
netperf -c hostname -f K
Last edited by Gen2ly (2009-11-17 19:08:38)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline