Untitled

mail@pastecode.io avatar
unknown
sh
a year ago
911 B
3
Indexable
# Define the URLs
urls=("http://example.com/url1" "http://example.com/url2")

# Create a script file to define the check_status_code function
echo '
check_status_code() {
    local url="$1"
    local http_code=$(curl -o /dev/null -s -I -w "%{http_code}" "$url")
    echo "$http_code"
}
' > check_status_script.sh

# Make the script executable
chmod +x check_status_script.sh

# Use xargs to run curl requests in parallel and collect the results
http_codes=($(printf "%s\n" "${urls[@]}" | xargs -I {} -P 2 bash -c './check_status_script.sh "$@"' _ {}))

# Initialize success to false
success=false

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

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