Advertisement
Dijit

latency_test.sh

Jun 30th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.96 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. set -e
  3.  
  4. unset CDPATH
  5. umask 0133
  6. unset verbose
  7.  
  8. ping_size=65507 #maximum legal ping packet (65535 - (20 + 8))
  9. ping_time=600 #ping time in seconds, actually is a counter since 1 ping = 1 second
  10.  
  11. us_leaseweb=199.58.84.5
  12. eu_leaseweb=37.48.113.186
  13.  
  14. us_i3d=162.244.55.135
  15. eu_i3d=31.204.159.20
  16.  
  17. function pretty_verbose(){
  18. case $1 in
  19.     # info
  20.     1) if [[ -v verbose ]]; then echo -e "[\033[0;32m*\033[0;0m] $2" ; fi
  21.     ;;
  22.     # error
  23.     2) >&2 echo -e "[\033[0;31m*\033[0;0m] $2"
  24.     ;;
  25.     #OMGWTFBBQ
  26.     *) echo -e "[\033[0;36m*\033[0;0m] $2"
  27.     ;;
  28. esac
  29. }
  30.  
  31. function lt_usage(){
  32.     echo -e "\e[1mUSAGE:\e[0m $0 -l us -v";
  33.     echo "   -l = Location and is required: us or eu";
  34.     exit 0;
  35. }
  36.  
  37. function ping_job(){
  38.     pretty_verbose 1 "Running $1, this will take $(($ping_time / 60)) minutes."
  39.     ip=${!2}
  40.     pretty_verbose 1 "Confirming: IP used for $1 is $ip"
  41.     ping -c $ping_time -s $ping_size $ip | awk 'BEGIN {FS="[=]|[ ]"} {print $10}' > .${1}.tmp
  42.     unset ip
  43.     sed -i '/^\s*$/d' .${1}.tmp
  44.     head -n $ping_time .${1}.tmp > ${1}-${location}.txt && rm .${1}.tmp
  45.     pretty_verbose 1 "Run of $1 complete"
  46. }
  47.  
  48. while getopts ":vl:" opt; do
  49.   case $opt in
  50.     v)
  51.       verbose="true"
  52.       pretty_verbose 1 "Verbose mode activated"
  53.       ;;
  54.     l)
  55.       i3d=${OPTARG}_i3d
  56.       i3d=${!i3d}
  57.       leaseweb=${OPTARG}_leaseweb
  58.       leaseweb=${!leaseweb}
  59.       location=${OPTARG}
  60.       pretty_verbose 1 "Location is: $OPTARG"
  61.       ;;
  62.     \?)
  63.       pretty_verbose 2 "Invalid option: -$OPTARG" >&2
  64.       ;;
  65.   esac
  66. done
  67.  
  68. if [[ -z $i3d ]]; then
  69.     pretty_verbose 2 "invalid location, script only supports eu or us";
  70.     lt_usage;
  71. fi
  72.  
  73. pretty_verbose 1 "using IPs $i3d for i3d and $leaseweb for leaseweb"
  74.  
  75. for vendor in i3d leaseweb; do
  76.     ping_job ${vendor} ${location}_${vendor}
  77. done
  78.  
  79. tar jcf latencytests.tbz2 i3d-${location}.txt leaseweb-${location}.txt && rm i3d-${location}.txt leaseweb-${location}.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement