#!/usr/bin/env bash set -e tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"} node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"} shift 2 index=${node#node-} ip="10.55.$index.77" connect_timeout_sec=3 function with_set_x() { set -x "$@" { ec=$? set +x return $ec } 2>/dev/null } case "$tool" in ping) with_set_x exec ping -W $connect_timeout_sec "$@" "$ip" ;; iperf3) port=5001 with_set_x exec iperf3 --client "$ip" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "$@" ;; curl) port=8080 with_set_x exec curl "http://$ip:$port/" -v --connect-timeout $connect_timeout_sec "$@" ;; ab) port=8080 with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/" ;; *) echo "Unknown tool: $tool" >&2 exit 2 ;; esac