Skip to content

Instantly share code, notes, and snippets.

@KylePDavis
Created March 26, 2014 03:30
Show Gist options
  • Select an option

  • Save KylePDavis/9776517 to your computer and use it in GitHub Desktop.

Select an option

Save KylePDavis/9776517 to your computer and use it in GitHub Desktop.

Revisions

  1. KylePDavis created this gist Mar 26, 2014.
    39 changes: 39 additions & 0 deletions get_url_stats.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash
    # A simple script to get the given URL with cURL and output stats.
    #
    # USAGE:
    # get_url_stats.sh <URL>
    #
    ###############################################################################

    out() { echo "`date +%Y%m%dT%H%M%SZ`: $*"; }
    err() { out "$*" 1>&2; }
    die() { err "EXIT: $1" && [ "$2" ] && [ "$2" -gte 0 ] && exit $2 || exit 1; }
    usage() { [ "$0" = "bash" ] || sed '2,/^##/p;d' "$0"; echo "$*"; exit 1; }
    [ "$1" = "--help" -o "$1" = "-h" ] && usage

    [ "$1" ] || usage

    [ "$FIELDS" ] || FIELDS="
    http_code
    http_connect
    num_connects
    num_redirects
    size_download
    size_header
    size_request
    size_upload
    speed_download
    speed_upload
    time_appconnect
    time_connect
    time_namelookup
    time_pretransfer
    time_redirect
    time_starttransfer
    time_total
    "

    FORMAT_STR="$(echo "$FIELDS" | egrep '^[a-z]' | awk '{print $1}' | sed 's/.*/&:%{&}/' | paste -sd ' ')\\n"

    exec curl -s -k -L -o/dev/null -w "$FORMAT_STR" "$@"