taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

check-urls (1165B)


      1 #!/bin/bash
      2 
      3 # Define colors for output
      4 RED='\033[0;31m'
      5 GREEN='\033[0;32m'
      6 YELLOW='\033[1;33m'
      7 NC='\033[0m' # No Color
      8 
      9 echo "Checking URLs from standard input..."
     10 echo "--------------------------------"
     11 
     12 # Loop through standard input line by line
     13 while IFS= read -r url || [ -n "$url" ]; do
     14     # Trim leading and trailing whitespace
     15     url=$(echo "$url" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
     16 
     17     # Skip empty lines or lines starting with #
     18     if [[ -z "$url" || "$url" =~ ^# ]]; then
     19         continue
     20     fi
     21 
     22     # Perform the check
     23     # -s: Silent mode (don't show progress bar)
     24     # -L: Follow redirects
     25     # -o /dev/null: Discard the response body
     26     # -w "%{http_code}": Print only the HTTP status code
     27     # --max-time 5: Timeout after 5 seconds to prevent hanging
     28     status_code=$(curl -s -L -o /dev/null -w "%{http_code}" --max-time 5 "$url")
     29 
     30     # Check the result
     31     if [ "$status_code" -eq 200 ]; then
     32         echo -e "${GREEN}[OK]  200${NC} : $url"
     33     elif [ "$status_code" -eq 000 ]; then
     34         echo -e "${RED}[ERR] CON${NC} : $url (Connection Failed)"
     35     else
     36         echo -e "${RED}[ERR] $status_code${NC} : $url"
     37     fi
     38 
     39 done