diff --git a/docker/bench/run-ab.sh b/docker/bench/run-ab.sh index 28d30ab..b26e648 100644 --- a/docker/bench/run-ab.sh +++ b/docker/bench/run-ab.sh @@ -100,7 +100,21 @@ done parse_to_csv() { local input="$1" local output="$2" - : > "$output" + local output_dir=$(dirname "$output") + + # Ensure the output directory exists + if [[ ! -d "$output_dir" ]]; then + mkdir -p "$output_dir" || { echo "Failed to create directory $output_dir"; exit 1; } + fi + + # Check if input file exists + if [[ ! -f "$input" ]]; then + echo "Input file $input does not exist." + exit 1 + fi + + : > "$output" # Clear output file before appending + grep -Eo 'https?://[^ ]+' "$input" | sort -u | while read -r url; do local ttfb_line=$(grep -m 1 "$url" "$input" | grep 'TTFB test passed' | awk -F'Mean TTFB: ' '{print $2}') local ab_line=$(grep -m 1 "$url" "$input" | grep 'ApacheBench test passed' | awk -F'Average time: ' '{print $2}') @@ -114,6 +128,7 @@ parse_to_csv() { done } + parse_to_csv "/logs/scan.log" "/logs/scan.csv" upload_to_hastebin() {