Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -e
- unset CDPATH
- umask 0133
- unset verbose
- ping_size=65507 #maximum legal ping packet (65535 - (20 + 8))
- ping_time=600 #ping time in seconds, actually is a counter since 1 ping = 1 second
- us_leaseweb=199.58.84.5
- eu_leaseweb=37.48.113.186
- us_i3d=162.244.55.135
- eu_i3d=31.204.159.20
- function pretty_verbose(){
- case $1 in
- # info
- 1) if [[ -v verbose ]]; then echo -e "[\033[0;32m*\033[0;0m] $2" ; fi
- ;;
- # error
- 2) >&2 echo -e "[\033[0;31m*\033[0;0m] $2"
- ;;
- #OMGWTFBBQ
- *) echo -e "[\033[0;36m*\033[0;0m] $2"
- ;;
- esac
- }
- function lt_usage(){
- echo -e "\e[1mUSAGE:\e[0m $0 -l us -v";
- echo " -l = Location and is required: us or eu";
- exit 0;
- }
- function ping_job(){
- pretty_verbose 1 "Running $1, this will take $(($ping_time / 60)) minutes."
- ip=${!2}
- pretty_verbose 1 "Confirming: IP used for $1 is $ip"
- ping -c $ping_time -s $ping_size $ip | awk 'BEGIN {FS="[=]|[ ]"} {print $10}' > .${1}.tmp
- unset ip
- sed -i '/^\s*$/d' .${1}.tmp
- head -n $ping_time .${1}.tmp > ${1}-${location}.txt && rm .${1}.tmp
- pretty_verbose 1 "Run of $1 complete"
- }
- while getopts ":vl:" opt; do
- case $opt in
- v)
- verbose="true"
- pretty_verbose 1 "Verbose mode activated"
- ;;
- l)
- i3d=${OPTARG}_i3d
- i3d=${!i3d}
- leaseweb=${OPTARG}_leaseweb
- leaseweb=${!leaseweb}
- location=${OPTARG}
- pretty_verbose 1 "Location is: $OPTARG"
- ;;
- \?)
- pretty_verbose 2 "Invalid option: -$OPTARG" >&2
- ;;
- esac
- done
- if [[ -z $i3d ]]; then
- pretty_verbose 2 "invalid location, script only supports eu or us";
- lt_usage;
- fi
- pretty_verbose 1 "using IPs $i3d for i3d and $leaseweb for leaseweb"
- for vendor in i3d leaseweb; do
- ping_job ${vendor} ${location}_${vendor}
- done
- 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