Skip to content

Instantly share code, notes, and snippets.

@jcipriano
Created July 11, 2017 21:49
Show Gist options
  • Save jcipriano/f784ca88e47ee55e48b056bda27289e6 to your computer and use it in GitHub Desktop.
Save jcipriano/f784ca88e47ee55e48b056bda27289e6 to your computer and use it in GitHub Desktop.
Shell script that uses curl to measure latency for a given URL.
#!/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
@jcipriano
Copy link
Author

jcipriano commented Jul 11, 2017

Setup & Running

  1. Copy contents to file and make executable.
    chmod +x latency.sh

  2. Run script by passing URL to measure latency on.
    ./latency.sh -u https://dev.twitter.com

Example Output:

Sending GET request to http://dev.twitter.com
----------------------------
    time_namelookup:  0.005
       time_connect:  0.012
    time_appconnect:  0.000
   time_pretransfer:  0.012
      time_redirect:  0.000
 time_starttransfer:  0.022
----------------------------
         time_total:  0.022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment