Skip to content

Instantly share code, notes, and snippets.

@MXMLN-sec
Last active June 14, 2017 11:24
Show Gist options
  • Save MXMLN-sec/4103e07c8c3672a5144c48fdff3ea453 to your computer and use it in GitHub Desktop.
Save MXMLN-sec/4103e07c8c3672a5144c48fdff3ea453 to your computer and use it in GitHub Desktop.
iperf Bash
#!/bin/bash
# Check dependencies
type iperf > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -e >&2 "\e[31mERROR 2: iperf is required but not installed\e[39m"
exit 1
fi
# Chack arguments
if [ "$#" -ne "3" ]; then
echo "ERROR: spezify the necessary arguments"
echo "Usage:"
echo "${0} [server] [runs] [seconds of each run]"
exit 2
else
host=$1
runs=$2
time=$3
fi
# Logging
log=`date +%F"_"%T`-iperf-$host.log
# Main
echo " ------------------------------------------------------------------"
echo " Results"
echo " ------------------------------------------------------------------"
echo " Server: $host Runs: $runs Duration/run: $time s"
echo " ------------------------------------------------------------------"
for run in $(seq 1 $runs); do
date=`date +%F" - "%X`
iperf -c $host -u -P 2 -f m -b 2048M -t $time >> "$log" &
sleep $(( $time+10 )); pkill iperf
if [[ $? -eq 0 ]]; then
echo " iperf was terminated due to not respoding"
else
echo -e " $date \t run $run: $(grep "SUM" $log | tail -1 | awk '{print "SUM: " $(NF-1) " " $(NF)}')"
fi
done
echo " ------------------------------------------------------------------"
echo
echo " see $log for details"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment