Iperf start stop script
Usage: iperfd <tcp|udp>
'query' shows all iperf servers which have their PIDs saved (and therefore can be stopped easily) whilst 'query-all' shows all instances of iperf (servers and clients) running on the server.
#!/bin/bash # This script sits on an iperf server and allows simple starting and stopping off iperf. Note, for # stopping you need to specify the port and protocol modeoption=$1 serverport=$2 operation=$3 mode="" if [ "$modeoption" = "udp" ]; then mode="-u" elif [ "$modeoption" = "tcp" ]; then mode="" elif [ "$modeoption" = "query-all" ]; then /bin/ps -fC iperf exit 0 elif [ "$modeoption" = "query" ]; then /bin/ls ./iperf*.pid exit 0 else echo "usage: iperfd <tcp|udp> <port number> <start|stop>, or iperfd <query|query-all> " exit 0 fi if [ "$operation" = "start" ]; then echo "Starting iperf on $modeoption port $serverport ..." /usr/bin/iperf -s -D -p $serverport $mode #Line below lists process IDs (-o pid), sorted by time, with no column # description (grep -v PID) and just the top line (head -1). This shoudl alsways get the PID # of the iperf just started! ps -C iperf -o pid --sort=-start_time | grep -v PID | head -1 > iperf-$modeoption$serverport.pid echo "... done" elif [ "$operation" = "stop" ]; then kill -9 `cat iperf-$modeoption$serverport.pid` echo "iperf server `cat iperf-$modeoption$serverport.pid` stopped" rm iperf-$modeoption$serverport.pid else echo "usage: iperfd <tcp|udp> <port number> <start|stop>, or iperfd <query|query-all> " exit 0 fi
– Main.TobyRodwell - 24 Jul 2007