#! /bin/bash declare -i samples=100 declare -a servers=('8.8.8.8') declare -i highestloss=0 declare -i alltimehighest=0 declare -i alltimelowest=100 declare -i iterations=1 while :; do highestloss=0 for server in "${servers[@]}"; do stats="$(ping "$server" -c "$samples" | tail -n 2 | head -n 1)" losspercent="$(echo "$stats" | cut -f6 -d ' ')" loss="${losspercent%\%}" [ -z "$loss" ] && continue if (( loss > highestloss )); then highestloss="$loss" fi done color="\e[34m" if (( highestloss > 0 )); then color="\e[31m" fi if (( highestloss > alltimehighest )); then alltimehighest="$highestloss" fi if (( highestloss < alltimelowest )); then alltimelowest="$highestloss" fi printf "\\rCurrent loss: $color%-3.3s\e[0m - \e[33m%-4.4s \e[34m%-4.4s \e[0m%-4.4s" \ "$highestloss" \ "$alltimehighest" \ "$alltimelowest" \ "$iterations" iterations="$(( iterations + 1 ))" sleep 1 done