diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..b6d3f10 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,34 @@ +# Compare Batches Script + +This directory contains the `compare_batches.sh` script for comparing batch data between two domains. + +## Usage + +To use the `compare_batches.sh` script: + +1. Make the script executable: + ```bash + chmod +x compare_batches.sh + ``` + +2. Run it with two domain names: + ```bash + ./compare_batches.sh localhost:1633 other_domain + ``` + +## What the script does + +The `compare_batches.sh` script: + +- Checks for correct number of arguments (requires exactly 2 domain names) +- Uses `curl -s` for silent mode to fetch `/batches` endpoint from both domains +- Pipes output through `jq` to format JSON +- Saves results to `1.txt` and `2.txt` +- Uses `diff --side-by-side --suppress-common-lines` to show only differing lines in a side-by-side format + - `--side-by-side` displays the differing lines from both files next to each other + - `--suppress-common-lines` ensures only differing lines are shown +- Reports if differences were found or not + +## Output + +The script will display differences between the two batch endpoints side by side, or report "No differences found" if the responses are identical. diff --git a/scripts/compare_batches.sh b/scripts/compare_batches.sh new file mode 100755 index 0000000..6f141eb --- /dev/null +++ b/scripts/compare_batches.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Check if two domain arguments are provided +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +DOMAIN1=$1 +DOMAIN2=$2 +FILE1="1.txt" +FILE2="2.txt" + +# Perform curl requests in parallel +curl -s "http://${DOMAIN1}/batches" | jq > "$FILE1" & +PID1=$! +curl -s "http://${DOMAIN2}/batches" | jq > "$FILE2" & +PID2=$! + +# Wait for both curl commands to complete +wait $PID1 +if [ $? -ne 0 ]; then + echo "Error fetching data from ${DOMAIN1}" + exit 1 +fi + +wait $PID2 +if [ $? -ne 0 ]; then + echo "Error fetching data from ${DOMAIN2}" + exit 1 +fi + +# Compare the files and show differences side by side +echo "Differences between ${FILE1} and ${FILE2} (side by side):" +diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2" + +# Check if there were any differences +if [ $? -eq 0 ]; then + echo "No differences found." +else + echo "Differences found (see above)." +fi