This is a Bash function named nk_ttfb() that measures the time-to-first-byte (TTFB) of a website. It takes one argument, which should be a domain name. If no argument is provided, the function will print an error message and return 0. The function then uses the curl command to retrieve the website, following any redirects, and limiting the query to 5 seconds. The -s option silences download progress and the -o option outputs the results to /dev/null since we don’t need them. Finally, the -w option is used to output the effective URL and the TTFB time in seconds.


[root@cloudvpsserver ~]# nk_ttfb domain.com
https://domain.com/ TTFB:0.210321


nk_ttfb() {
# nk_ttfb expects a domain to be passed. Print message and exit if one isn't.
if [ "$1" = "" ]; then
    echo "You must provide a domain"
    return 0
# Use curl to get the ttfb of the site.
# -L to follow links so that a 301 doesn't influence it
# -m 5 limit the query to 5 seconds.
# -s Be silent about the download info.
# -o output the results to /dev/null since we don't need them.
# -w write out, url_effective(siteurl) and time_starttransfer(ttfb)
curl -L -m 5 -s -o /dev/null https://"$1" -w "%{url_effective} TTFB:%{time_starttransfer}\n"

Author: Nichole Kernreicht

Created: 2023-04-09 Sun 21:17