Created
July 11, 2017 21:49
-
-
Save jcipriano/f784ca88e47ee55e48b056bda27289e6 to your computer and use it in GitHub Desktop.
Shell script that uses curl to measure latency for a given URL.
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 | |
# parse command line options | |
while [[ $# -gt 1 ]] | |
do | |
key="$1" | |
case $key in | |
-u|--url) | |
target_url="$2" | |
shift # past argument | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
shift # past argument or value | |
done | |
format="---------------------------- | |
time_namelookup: %{time_namelookup} | |
time_connect: %{time_connect} | |
time_appconnect: %{time_appconnect} | |
time_pretransfer: %{time_pretransfer} | |
time_redirect: %{time_redirect} | |
time_starttransfer: %{time_starttransfer} | |
---------------------------- | |
time_total: %{time_total}\n" | |
if [ "$target_url" ]; then | |
echo "Sending GET request to $target_url" | |
curl -w "$format" -o /dev/null -s "$target_url" | |
else | |
echo "Target URL not specified." | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup & Running
Copy contents to file and make executable.
chmod +x latency.sh
Run script by passing URL to measure latency on.
./latency.sh -u https://dev.twitter.com
Example Output: