90 Snippets: Sending some https requests ๐ŸŒŽ

90 Snippets: Sending some https requests ๐ŸŒŽ

90 Projects towards mastery - Day 06 ๐ŸŽ‰


3 min read

Greetings, fellow developers and shell scripting enthusiasts! It's a new day, and with it comes a fresh challenge to conquer. Today, we delve into the mystical arts of website status checking with our trusty bash script, webstat. In our ongoing quest for proficiency, we continue to refine our skills, mastering one script at a time.

The Script's Enchantment

Welcome to Day 06, where the bash script webstat takes center stage. As we tackle new horizons, our confidence surges, and the arcane world of shell scripting becomes familiar territory. So, let's unravel the magic woven within this script and understand how it deftly checks the status of websites.

Full code here

The Day's Objective

Today, we aim to craft a powerful tool that can check the status of websites, revealing whether they are up and running or hidden in the shadows. With webstat, we can navigate this digital realm with finesse and precision.

The Code's Brilliance: A Closer Look

As the sun rises on this coding adventure, let's break down the script into fragments of understanding:

  1. Help and Manual Mastery:
function manual(){
    # ... (manual content)

# Check for arguments and provide help or manual
if [[ $ARGS_COUNT == 0 ]]; then
    echo -e "${RED_BOLD}Error: no arguments provided${RESET}"
    exit 1

if [[ $ARGS_COUNT == 1 ]]; then
    if [[ $1 == "-h" || $1 == "--help" ]]; then

Our script begins with a splendid manual that echoes clarity and wisdom. Run it with no arguments or -h/--help, and you'll be welcomed by the script's purpose and usage instructions.

  1. Status Insight Function:
function print_message(){
    # ... (status cases and messages)

The script's heart lies within this function. It receives an HTTP response code and beautifully crafts status messages based on it. Whether a website is up, non-existent, or something else, this function sheds light on its current state.

  1. Weaving the Magic:
for arg in "$@"; do
    if [[ $arg == "-f" || $arg == "--file" ]]; then
        # ... (file reading and website checking)
    elif [[ $arg != "" && $arg == "https://"* ]]; then
        # ... (website checking)

In this spellbinding loop, the script works its magic. With the ability to check individual websites or read from a file, it unveils the mystical HTTP response codes and casts them into human-readable messages.

The Script's Grand Finale

As the script completes its enchantments, it offers you a moment to reflect upon the journey. The digital world's secrets have been unveiled, and your skill as a webstat wizard has grown.

By Thor, By Odin, Let's Master the Web

With Day 06 at its conclusion, you emerge with newfound prowess in website status checking. As developers, we continue to harness the power of the shell, transforming complexity into comprehensible scripts.

Keep your eyes peeled for more exhilarating chapters in our saga. Until next time, remember: By Thor, By Odin, let's keep scripting and master this digital realm!

Embrace the magic of the shell, and may your scripts always be cast in your favor.