Last active
September 22, 2019 13:31
-
-
Save miticojo/5feb93b5b19a69e53f3de6da886636ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
APIURL=https://speech.googleapis.com | |
REMOTEIP=$(curl -s ipinfo.io/ip) | |
REMOTEASN=$(curl -s ipinfo.io/org | cut -d' ' -f1) | |
RESULTFILE="google-ping-api-results-$(date +%s).csv" | |
## Script start time | |
START=$(date +%s) | |
## Total run time | |
DURRATION=$((60 * 60 * 24)) | |
## Total running time | |
UPTIME=$(($(date +%s) - $START)) | |
echo "==========================================" | |
echo "Starting 24h connection test to $APIURL..." | |
echo "Results are written into $RESULTFILE" | |
echo "==========================================" | |
sleep 2 | |
( | |
echo "timestamp,remote_ip,remote_asn,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,time_total" | |
while [[ $UPTIME -le $DURRATION ]]; do | |
curl -s -o /dev/null \ | |
-w "%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}\n" \ | |
$APIURL | xargs -L 1 echo "$(date +'%s'),$REMOTEIP,$REMOTEASN,$1" | |
## Sleep for a bit | |
sleep 2 | |
## Update running time | |
UPTIME=$(($(date +%s) - $START)) | |
done | |
) | tee $RESULTFILE | |
echo "==========================================" | |
echo "Connection test completed with success. Please send back the results file $RESULTFILE for analisys." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results should be like these: