Skip to content
Snippets Groups Projects

check website status

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Quentin Bramas
    Edited
    check_website.sh 1.34 KiB
    #!/bin/bash
    
    # Check if URL is provided as an argument
    if [ -z "$1" ]; then
        echo "Usage: $0 <URL>"
        exit 1
    fi
    
    # Use the first argument as the URL to check
    URL=$1
    
    # Function to check website status
    check_website() {
        # Attempt to fetch the website with a 10-second timeout
        response=$(curl -s --max-time 10 --connect-timeout 10 -o /dev/null -w "%{http_code}" "$URL")
        if [ $? -eq 0 ]; then
            osascript -e 'display notification "'"$URL"' is up" with title "Website Status"'
        else
            echo "$URL is down or not responding"
        fi
    }
    
    # Function to display a pretty progress bar for 60 seconds
    show_progress_bar() {
        local duration=60
        local interval=1
        local bar_length=20
        local elapsed=0
    
        while [ $elapsed -lt $duration ]; do
            sleep $interval
            elapsed=$((elapsed + interval))
            completed=$((elapsed * bar_length / duration))
            remaining=$((bar_length - completed))
    
            # Build the progress bar
            bar=$(printf "%${completed}s" | tr ' ' '=')
            bar=$(printf "%s>" "$bar")
            bar=$(printf "%-${bar_length}s" "$bar")
    
            # Print the progress bar
            printf "\r[%s] %d seconds" "$bar" "$elapsed"
        done
        echo ""  # Move to the next line after the progress bar is complete
    }
    
    # Infinite loop to check every minute
    while true; do
        check_website
        show_progress_bar
    done
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment