Skip to content

Instantly share code, notes, and snippets.

@hu0p
Created February 14, 2020 00:13
Show Gist options
  • Save hu0p/d936732497bae9399e3533d2bc09dbcb to your computer and use it in GitHub Desktop.
Save hu0p/d936732497bae9399e3533d2bc09dbcb to your computer and use it in GitHub Desktop.
Check Time to First Byte for a list of sites
#!/bin/bash
# file: ttfb.sh
# check the TTFB for a list of sites
# add list of sites here
declare -a sites=()
# test results will be output here
rm -rf $HOME/Desktop/TTFB-`date +"%m-%d-%Y"`.csv
echo "TTFB Test on: `date +"%m-%d-%Y %H:%M"`\n URL, Connect, TTFB, Total Time" | cat >> $HOME/Desktop/TTFB-`date +"%m-%d-%Y"`.csv
# status
echo "Running TTFB test for: "
# loop over sites and output each TTFB result to CSV
for i in "${!sites[@]}"
do
printf "\r"
tput el
printf "${sites[$i]}..."
curl -w '%{url_effective},%{time_connect},%{time_starttransfer},%{time_total}\n' -o /dev/null -s ${sites[$i]} | cat >> $HOME/Desktop/2060-TTFB-`date +"%m-%d-%Y"`.csv
printf "Finished."
sleep .1
done
# clean up and say we're done
printf "\r"
tput el
tput cuu 1
tput el
echo "TTFB Test Completed "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment