Nk_respones_codes
Description
This is a Bash function named nk_response_codes()
that retrieves the HTTP response codes of multiple websites. It does this by calling another function called gen_response_code_list, which first prints a table header, and then uses a loop to iterate over all the domains obtained via another function calle nk_list_all_domains() . For each domain, curl is used 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 HTTP response code.
The gen_response_code_list()
function outputs the results in a format that is then passed through the column command to format the output as a table before being displayed to the user.
Example
[root@cloudvpsserver ~]# nk_response_codes Domain Response-Code nkern.net 200
Code
nk_response_codes() { # nk_respones_codes is basically a wrapper around gen_respose_code_list that formats the output. gen_response_code_list() { # First Print out the headers echo "Domain Response-Code" # Now for every domain on the server. Obtained via running nk_list_all_domains for domain in $(nk_list_all_domains); do # Print out the domain name and it's curl result. # -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, report back the response_code echo "$domain" "$(curl -m 5 -s -L -o /dev/null https://"$domain" -w "%{response_code}\n")" ; done } # run gen_response_code_list and format the results as a table. gen_response_code_list | column -t }