Untitled

 avatar
unknown
sh
a year ago
873 B
7
Indexable
# Define the URLs
urls=("http://example.com/url1" "http://example.com/url2")

# Initialize an associative array to store HTTP status codes
declare -A http_codes

# Create a named pipe for each URL
for url in "${urls[@]}"; do
    mkfifo "$url.pipe"
done

# Run curl requests in parallel using &
for url in "${urls[@]}"; do
    (http_code=$(curl -o "$url.pipe" -s -I -w "%{http_code}" "$url")
    http_codes["$url"]=$http_code
    rm "$url.pipe"
    ) &
done

# Wait for all background jobs to finish
wait

# Check the HTTP status codes after the background jobs are completed
success=true

for url in "${urls[@]}"; do
    if [ "${http_codes[$url]}" != "200" ]; then
        success=false
        break
    fi
done

if $success; then
    echo "All requests returned 200 OK."
else
    echo "At least one request did not return 200 OK."
fi
Editor is loading...