Skip to content

Instantly share code, notes, and snippets.

@mbierman
Created March 31, 2014 18:10
Show Gist options
  • Save mbierman/9898511 to your computer and use it in GitHub Desktop.
Save mbierman/9898511 to your computer and use it in GitHub Desktop.
Get some idea of how network latency is doing.
#!/usr/bin/env bash
#Variables
count=0
max=45
sleept=1
maxsleep=15
domain=www.oracle.com
while [ "$count" -eq 0 ]; do
tme=$(ping -c1 $domain | grep from | cut -f4 -d '=' | sed 's/ ms//g' )
tmr=$(ping -c1 $domain | grep -oh 'Request timeout\|100.0% packet loss\|Unknown host\|illegal character')
echo -e $tme $tmr
if [[ -n $tmr ]]; then
echo -e "----\t$(date +"%m/%d/%Y %k:%M:%S") "| tee -a Oracle.txt
sleept=1
fi
case `echo "tme=$tme;max=$max;r=-1;if(tme==max)r=0;if(tme>max)r=1;r"|bc` in
0) if [ "$sleept" -lt $maxsleep ]; then ((sleept++)); fi # $tme and $max are equal
;; 1) echo -e "$tme\t$(date +"%m/%d/%Y %k:%M:%S")" | tee -a Oracle.txt ; sleept=1
;; *) if [ "$sleept" -lt $maxsleep ]; then ((sleept++)); fi; echo sleept is: $sleept # echo tme=$tme is less then max=$max
;; esac
sleep $sleept
# ((count++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment