#!/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.log" local total_ttfb sum_ttfb mean_ttfb for url in "${urls[@]}"; do total_ttfb=0 for i in {1..5}; do ttfb=$(curl -o /dev/null -s -w "%{time_starttransfer}\n" -u "$username:$password" "$url") total_ttfb=$(echo "$total_ttfb + $ttfb" | bc) done sum_ttfb=$total_ttfb mean_ttfb=$(echo "scale=3; $sum_ttfb / 5" | bc) echo "$url TTFB Mean: $mean_ttfb seconds" | tee -a "$log_file" done } function prepare_log_file { local log_file="/logs/authenticated.log" > "$log_file" mkdir -p $(dirname "$log_file") touch "$log_file" } prepare_log_file test_urls run_apache_bench check_ttfb_and_log