#!/bin/bash function test_urls { local urls=(${URLS//,/ }) local username=$USERNAME local password=$PASSWORD for url in "${urls[@]}"; do curl -u "$username:$password" "$url" done } function run_apache_bench { local urls=(${URLS//,/ }) local username=$USERNAME local password=$PASSWORD local requests=$REQUESTS local concurrency=$CONCURRENCY local log_file="/logs/authenticated.log" for url in "${urls[@]}"; do ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" | tee -a "$log_file" done } function check_ttfb_and_log { local urls=(${URLS//,/ }) local username=$USERNAME local password=$PASSWORD local log_file="/logs/authenticated.csv" local total_ttfb sum_ttfb mean_ttfb http_code echo "URL,Username,HTTP Code,Mean TTFB" > "$log_file" for url in "${urls[@]}"; do total_ttfb=0 for i in {1..5}; do response=$(curl -o /dev/null -s -w "%{http_code},%{time_starttransfer}\n" -u "$username:$password" "$url") http_code=$(echo "$response" | cut -d',' -f1) ttfb=$(echo "$response" | cut -d',' -f2) total_ttfb=$(echo "$total_ttfb + $ttfb" | bc) done sum_ttfb=$total_ttfb mean_ttfb=$(echo "scale=3; $sum_ttfb / 5" | bc) echo "$url,$username,$http_code,$mean_ttfb" | tee -a "$log_file" done } function prepare_log_file { local log_file="/logs/authenticated.csv" > "$log_file" mkdir -p $(dirname "$log_file") touch "$log_file" } prepare_log_file test_urls run_apache_bench check_ttfb_and_log