#!/bin/bash # Function to check a single webpage check_webpage() { local url=$(echo "$1" | tr -d '\r') # Remove carriage returns local base_url=$(echo "$2" | tr -d '\r') local full_url="${base_url}${url}" local timeout=10 echo -n "Testing $full_url ... " # Use curl to fetch the page with timeout response=$(curl -s -w "\n%{http_code}" --max-time $timeout "$full_url") if [ $? -ne 0 ]; then echo "FAILED - Connection error or timeout $full_url " return 1 fi # Split response into body and status code HTTP_STATUS=$(echo "$response" | tail -n1) BODY=$(echo "$response" | sed '$d') # Check HTTP status if [ "$HTTP_STATUS" != "200" ]; then echo "FAILED - HTTP Status: $HTTP_STATUS" return 1 fi # Check if response contains HTML if ! printf '%s' "$BODY" | grep -q "\|&2; usage ;; esac done # Check if URL file is provided if [ -z "$url_file" ]; then echo "Error: URL file is required" usage fi # Check if URL file exists if [ ! -f "$url_file" ]; then echo "Error: URL list file not found: $url_file" exit 1 fi # Run tests using the URL list if test_all_urls "$url_file" "$base_url"; then echo "All webpage tests passed!" exit 0 else echo "Some webpage tests failed!" exit 1 fi } # Run main if script is executed directly if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "$@" fi