Skip to content

Instantly share code, notes, and snippets.

@MXMLN-sec
Created June 12, 2017 14:47
Show Gist options
  • Save MXMLN-sec/343841aad658fcbe3dacf1e46ae1f32d to your computer and use it in GitHub Desktop.
Save MXMLN-sec/343841aad658fcbe3dacf1e46ae1f32d 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 3
else
runs=$1
time=$2
host=$3
fi
# Logging
log=`date +%F" - "%X`-iperf-$host.log
# Main
echo " Results"
echo " ------------------------------------------------------------------"
echo " Server: $host Runs: $run Duration/run: $time
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 wurde mit killall beendet"
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