#!/bin/bash function prepare_log_file { local log_file="/logs/authenticated.csv" > "$log_file" mkdir -p $(dirname "$log_file") touch "$log_file" } function run_apache_bench_and_check_ttfb { local urls=(${URLS//,/ }) local username=$USERNAME local password=$PASSWORD local requests=$REQUESTS local concurrency=$CONCURRENCY local log_file="/logs/authenticated.csv" echo "URL,Username,HTTP Code,Average TTFB (ms),AB Mean Time per Request (ms)" | tee "$log_file" for url in "${urls[@]}"; do local total_ttfb=0 local ttfb=0 local http_code=$(curl -o /dev/null -s -w "%{http_code}" -u "$username:$password" "$url") # Apache Bench local ab_summary=$(ab -n "$requests" -c "$concurrency" -A "$username:$password" "$url" 2>&1 | grep "Time per request" | head -1) local ab_mean_time_per_request=$(echo "$ab_summary" | awk '{print $4}' | awk '{printf "%.3f", $1}') # TTFB 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 -l) done local mean_ttfb=$(echo "scale=3; ($total_ttfb / 5) * 1000" | bc) echo "$url,$username,$http_code,${mean_ttfb},${ab_mean_time_per_request}" | tee -a "$log_file" done } function upload_to_hastebin_and_notify { local log_file="/logs/authenticated.csv" local response=$(curl -X POST -s --data-binary @"${log_file}" https://haste.nixc.us/documents) local key=$(echo $response | awk -F '"' '{print $4}') if [ ! -z "$key" ]; then local haste_url="https://haste.nixc.us/$key" echo "Logs uploaded to: $haste_url" # Send notification with the Haste URL, including the authentication token curl -X POST -H "Authorization: Bearer tk_xjkgklandq47adj1f17bw6edtilh4" -d "$haste_url" https://ntfy.nixc.us/bnHobG80sO5ZF4SB else echo "Failed to upload logs to Hastebin." fi } prepare_log_file run_apache_bench_and_check_ttfb upload_to_hastebin_and_notify