From 5e596bdef700311890a7c67eda38b599611e5045 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 11:11:49 -0500 Subject: [PATCH 01/31] added variable length receiving and sending --- MP1/client.py | 24 ++++++++++++++++++++++-- MP1/server.py | 26 +++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index 8dac95a..d8ba792 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -15,6 +15,26 @@ ALL_IPS = [ "172.22.156.6" ] +def send_message(sock, message): + e_data = message.encode('utf-8') + #header for the message length + header = str(len(e_data)).zfill(10).encode('utf-8') + sock.sendall(header) + sock.sendall(e_data) + +def receive_message(sock): + header = sock.recv(10) + if not header: + return None + message_length = int(header.decode('utf-8')) + received_data = b"" + while len(received_data) < message_length: + chunk = sock.recv(65536) + if not chunk: + break + received_data += chunk + return received_data.decode('utf-8') + def grep_all_ips(ips, cmd): match_count = [] @@ -26,8 +46,8 @@ def grep_all_ips(ips, cmd): full_cmd = cmd + f" ./machine.{i + 1}.log" - client_socket.sendall(full_cmd.encode()) - data = client_socket.recv(65536).decode() + send_message(client_socket, full_cmd) + data = receive_message(client_socket) count = len(data.splitlines()) match_count.append(count) diff --git a/MP1/server.py b/MP1/server.py index 19e2cf0..d7b2253 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -13,11 +13,31 @@ server_socket.listen() print(f"Server listening on {HOST}:{PORT}") +def send_message(sock, message): + e_data = message.encode('utf-8') + #header for the message length + header = str(len(e_data)).zfill(10).encode('utf-8') + sock.sendall(header) + sock.sendall(e_data) + +def receive_message(sock): + header = sock.recv(10) + if not header: + return None + message_length = int(header.decode('utf-8')) + received_data = b"" + while len(received_data) < message_length: + chunk = sock.recv(65536) + if not chunk: + break + received_data += chunk + return received_data.decode('utf-8') + while True: conn, addr = server_socket.accept() print(f"Connected by {addr}") - command = conn.recv(65536) + command = receive_message(conn) # print("Received Grep Command:", command.decode()) command_args = shlex.split(command.decode()) @@ -32,8 +52,8 @@ while True: result = subprocess.run(command_args, capture_output=True, text=True) - conn.sendall(result.stdout.encode()) + send_message(conn, result.stdout) conn.close() -server_socket.close() \ No newline at end of file +server_socket.close() From 2ec0be3a8260ff18e7b0bd0ade784c95fb964666 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 11:18:28 -0500 Subject: [PATCH 02/31] Update server.py --- MP1/server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MP1/server.py b/MP1/server.py index d7b2253..3598aaa 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -38,13 +38,15 @@ while True: print(f"Connected by {addr}") command = receive_message(conn) - # print("Received Grep Command:", command.decode()) + if command is None: + conn.close() + continue - command_args = shlex.split(command.decode()) + command_args = shlex.split(command) if not command_args or command_args[0] != "grep": response = "Invalid command. Please use the 'grep' command." - conn.sendall(response.encode()) + send_message(conn, response) conn.close() continue From a9b4edd040156d875c1f26d4b8ebf8636a78b26a Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 12:31:42 -0500 Subject: [PATCH 03/31] Update server.py --- MP1/server.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/MP1/server.py b/MP1/server.py index 3598aaa..1c5fa6f 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -20,17 +20,21 @@ def send_message(sock, message): sock.sendall(header) sock.sendall(e_data) -def receive_message(sock): - header = sock.recv(10) - if not header: - return None - message_length = int(header.decode('utf-8')) +def receive_exact(sock, num_bytes): received_data = b"" - while len(received_data) < message_length: - chunk = sock.recv(65536) + while len(received_data) < num_bytes: + chunk = sock.recv(num_bytes - len(received_data)) if not chunk: break received_data += chunk + return received_data + +def receive_message(sock): + header = receive_exact(sock, 10) + if not header: + return None + message_length = int(header.decode('utf-8')) + received_data = receive_exact(sock, message_length) return received_data.decode('utf-8') while True: From ca1073bedaffb91a7882aec662fc3462e3ccb9ca Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 12:34:08 -0500 Subject: [PATCH 04/31] Update client.py --- MP1/client.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index d8ba792..cfa9d63 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -22,17 +22,21 @@ def send_message(sock, message): sock.sendall(header) sock.sendall(e_data) -def receive_message(sock): - header = sock.recv(10) - if not header: - return None - message_length = int(header.decode('utf-8')) +def receive_exact(sock, num_bytes): received_data = b"" - while len(received_data) < message_length: - chunk = sock.recv(65536) + while len(received_data) < num_bytes: + chunk = sock.recv(num_bytes - len(received_data)) if not chunk: break received_data += chunk + return received_data + +def receive_message(sock): + header = receive_exact(sock, 10) + if not header: + return None + message_length = int(header.decode('utf-8')) + received_data = receive_exact(sock, message_length) return received_data.decode('utf-8') def grep_all_ips(ips, cmd): From 249f0b844b3d6c3363fc6cb4ba96b09ebf1ef230 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 19:22:35 -0500 Subject: [PATCH 05/31] scripts --- MP1/scripts/deploy_mp.sh | 9 +++++++++ MP1/scripts/install_cmd.sh | 0 MP1/scripts/kill_mp.sh | 15 +++++++++++++++ MP1/scripts/run_mp.sh | 33 +++++++++++++++++++++++++++++++++ MP1/server.py | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 MP1/scripts/deploy_mp.sh mode change 100644 => 100755 MP1/scripts/install_cmd.sh create mode 100755 MP1/scripts/kill_mp.sh create mode 100755 MP1/scripts/run_mp.sh diff --git a/MP1/scripts/deploy_mp.sh b/MP1/scripts/deploy_mp.sh new file mode 100755 index 0000000..d28f118 --- /dev/null +++ b/MP1/scripts/deploy_mp.sh @@ -0,0 +1,9 @@ +#/usr/bin/env bash + +/Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/kill_mp.sh all + +for i in {1..10}; do + vpn ssh -n -f -o BatchMode=yes "server$i" "cd fa26_cs425_.group-mp_.team-01/MP1 && git pull origin aryan && /Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/install_cmd.sh" +done + +/Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/run_mp.sh all \ No newline at end of file diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh old mode 100644 new mode 100755 diff --git a/MP1/scripts/kill_mp.sh b/MP1/scripts/kill_mp.sh new file mode 100755 index 0000000..446205b --- /dev/null +++ b/MP1/scripts/kill_mp.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +if [[ "$1" == "all" ]]; then + for i in {1..10}; do + echo "Killing server$i..." + vpn ssh -o BatchMode=yes "server$i" "fuser -k -9 5055/tcp" + echo "" + done +else + for i in "$@"; do + echo "Killing server$i..." + vpn ssh -o BatchMode=yes "server$i" "fuser -k -9 5055/tcp" + echo "" + done +fi \ No newline at end of file diff --git a/MP1/scripts/run_mp.sh b/MP1/scripts/run_mp.sh new file mode 100755 index 0000000..e38b8e1 --- /dev/null +++ b/MP1/scripts/run_mp.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +CMD='cd fa26_cs425_.group-mp_.team-01/MP1 && nohup python3 server.py /dev/null 2>&1 &' + +if [[ "$#" -eq 0 ]]; then + echo "Need at least one server number as an argument." + exit 1 +fi + +if [[ "$1" == "all" ]]; then + TARGETS="1 2 3 4 5 6 7 8 9 10" +else + TARGETS="$@" +fi + +echo "Starting servers" + +for i in $TARGETS; do + vpn ssh -n -f -o BatchMode=yes "server$i" "$CMD" +done + +sleep 2 + +for i in $TARGETS; do + pid=$(vpn ssh -n -o BatchMode=yes "server$i" "pgrep -o -u \$USER -f '[p]ython3 server.py'") + + if [[ -n "$pid" ]]; then + pid_clean=$(echo "$pid" | tr '\n' ' ') + echo "Server$i is running with PID(s): $pid_clean" + else + echo "Server$i is not running." + fi +done diff --git a/MP1/server.py b/MP1/server.py index 1c5fa6f..38ac702 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -58,7 +58,7 @@ while True: result = subprocess.run(command_args, capture_output=True, text=True) - send_message(conn, result.stdout) + send_message(conn, result.stdout + result.stderr) conn.close() From cc539814d86940cce761f5c245c5818d3e36aceb Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 19:59:00 -0500 Subject: [PATCH 06/31] minor fix --- MP1/client.py | 3 ++- MP1/server.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index cfa9d63..0fd6e1f 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -27,7 +27,7 @@ def receive_exact(sock, num_bytes): while len(received_data) < num_bytes: chunk = sock.recv(num_bytes - len(received_data)) if not chunk: - break + raise ConnectionError("connection closed before the full message arrived") received_data += chunk return received_data @@ -62,6 +62,7 @@ def grep_all_ips(ips, cmd): except Exception as e: print(f"Failed to connect to {ip}:{PORT} - {e}") + match_count.append(0) finally: client_socket.close() diff --git a/MP1/server.py b/MP1/server.py index 38ac702..147b896 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -25,7 +25,7 @@ def receive_exact(sock, num_bytes): while len(received_data) < num_bytes: chunk = sock.recv(num_bytes - len(received_data)) if not chunk: - break + raise ConnectionError("connection closed before the full message arrived") received_data += chunk return received_data @@ -56,7 +56,7 @@ while True: command_args.insert(1, "-n") - result = subprocess.run(command_args, capture_output=True, text=True) + result = subprocess.run(command_args, cwd="~/fa26_cs425_.group-mp_.team-01/MP1" capture_output=True, text=True) send_message(conn, result.stdout + result.stderr) From 6088a16f8fd707821f55f9c08715dc3be8e0960c Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:17:57 -0500 Subject: [PATCH 07/31] Update server.py --- MP1/server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MP1/server.py b/MP1/server.py index 147b896..b3893f5 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -2,6 +2,7 @@ import socket import shlex import subprocess +from pathlib import Path HOST = "0.0.0.0" PORT = 5055 @@ -11,6 +12,8 @@ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind((HOST, PORT)) server_socket.listen() +SCRIPT_DIR = Path(__file__).resolve().parent + print(f"Server listening on {HOST}:{PORT}") def send_message(sock, message): @@ -56,7 +59,7 @@ while True: command_args.insert(1, "-n") - result = subprocess.run(command_args, cwd="~/fa26_cs425_.group-mp_.team-01/MP1" capture_output=True, text=True) + result = subprocess.run(command_args, cwd=SCRIPT_DIR, capture_output=True, text=True) send_message(conn, result.stdout + result.stderr) From 1c8d9540cc53aa40d30131572defde4ba945ca92 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:23:38 -0500 Subject: [PATCH 08/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 34a5f30..f406312 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,3 +1,4 @@ +rm ~/bin chmod +x ../client.py mkdir -p ~/bin cp ../client.py ~/bin/grepp From c768497724fe1154aa78c300a4c35f8471866bb7 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:25:40 -0500 Subject: [PATCH 09/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index f406312..7f490fb 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,4 +1,4 @@ -rm ~/bin +rm -rf ~/bin chmod +x ../client.py mkdir -p ~/bin cp ../client.py ~/bin/grepp From ed8160539f9f2933f8bd37ead407f1364a01030b Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:28:10 -0500 Subject: [PATCH 10/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 7f490fb..2c3214c 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -3,5 +3,5 @@ chmod +x ../client.py mkdir -p ~/bin cp ../client.py ~/bin/grepp chmod +x ~/bin/grepp -export PATH="$HOME/bin:$PATH" > ~/.bashrc +echo "export PATH=\"$HOME/bin:$PATH\"" > ~/.bashrc source ~/.bashrc \ No newline at end of file From bec05d372d04959776023c7389c85ea295984e1c Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:30:37 -0500 Subject: [PATCH 11/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 2c3214c..991935a 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -3,5 +3,5 @@ chmod +x ../client.py mkdir -p ~/bin cp ../client.py ~/bin/grepp chmod +x ~/bin/grepp -echo "export PATH=\"$HOME/bin:$PATH\"" > ~/.bashrc +echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc source ~/.bashrc \ No newline at end of file From 1bd5bf4e5c3a94b9a44d62aa3cef429f5a301957 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:35:54 -0500 Subject: [PATCH 12/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 991935a..2ed7e4f 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,7 +1,6 @@ -rm -rf ~/bin +rm -rf "$HOME/bin/grepp" chmod +x ../client.py -mkdir -p ~/bin -cp ../client.py ~/bin/grepp -chmod +x ~/bin/grepp -echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc +mkdir -p "$HOME/bin" +install -m 755 ../client.py "$HOME/bin/grepp" +echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc" source ~/.bashrc \ No newline at end of file From 5f342cbb47924c5472188fab1003122955c52550 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:37:38 -0500 Subject: [PATCH 13/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 2ed7e4f..463fe9c 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -3,4 +3,5 @@ chmod +x ../client.py mkdir -p "$HOME/bin" install -m 755 ../client.py "$HOME/bin/grepp" echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc" -source ~/.bashrc \ No newline at end of file +source ~/.bashrc +hash -r \ No newline at end of file From df3de85db0a789e3d20146bb7dfced74f25187b7 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:39:39 -0500 Subject: [PATCH 14/31] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 463fe9c..9724ff0 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,7 +1,6 @@ rm -rf "$HOME/bin/grepp" -chmod +x ../client.py mkdir -p "$HOME/bin" install -m 755 ../client.py "$HOME/bin/grepp" echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc" -source ~/.bashrc -hash -r \ No newline at end of file +hash -r +source "$HOME/.bashrc" \ No newline at end of file From 76cc910260af3e1a5d027f3a48e65864348bfdab Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:43:38 -0500 Subject: [PATCH 15/31] Update client.py --- MP1/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index 0fd6e1f..0576f7a 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -74,7 +74,6 @@ while True: print("=========================== SUMMARY ===========================") for i, count in enumerate(match_count): - if count > 0: print(f"machine.{i + 1}.log: {count} matches") print(f"Total matches: {sum(match_count)}") print("===============================================================") \ No newline at end of file From 14a6ac78fc767f9c0cc1ecfe6a73ee875839f666 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:48:10 -0500 Subject: [PATCH 16/31] Update client.py --- MP1/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index 0576f7a..8195f4a 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -62,7 +62,7 @@ def grep_all_ips(ips, cmd): except Exception as e: print(f"Failed to connect to {ip}:{PORT} - {e}") - match_count.append(0) + match_count.append(-1) finally: client_socket.close() @@ -74,6 +74,9 @@ while True: print("=========================== SUMMARY ===========================") for i, count in enumerate(match_count): + if count == -1: + print(f"machine.{i + 1}.log: Connection failed") + else: print(f"machine.{i + 1}.log: {count} matches") print(f"Total matches: {sum(match_count)}") print("===============================================================") \ No newline at end of file From 1771235d61b0cbd3c4031f9ec99ab842776b2a75 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:49:55 -0500 Subject: [PATCH 17/31] Update client.py --- MP1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index 8195f4a..91d5d83 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -78,5 +78,5 @@ while True: print(f"machine.{i + 1}.log: Connection failed") else: print(f"machine.{i + 1}.log: {count} matches") - print(f"Total matches: {sum(match_count)}") + print(f"Total matches: {max(0, sum(match_count))}") print("===============================================================") \ No newline at end of file From b606caa688a2fd65309c9918ced2db68cfd974ef Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:51:46 -0500 Subject: [PATCH 18/31] Update client.py --- MP1/client.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index 91d5d83..0bd4618 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -68,15 +68,17 @@ def grep_all_ips(ips, cmd): return match_count -while True: - cmd = input(">> ").strip() - match_count = grep_all_ips(ALL_IPS, cmd) +#get all the argument of call +import sys - print("=========================== SUMMARY ===========================") - for i, count in enumerate(match_count): - if count == -1: - print(f"machine.{i + 1}.log: Connection failed") - else: - print(f"machine.{i + 1}.log: {count} matches") - print(f"Total matches: {max(0, sum(match_count))}") - print("===============================================================") \ No newline at end of file +cmd = " ".join(sys.argv[1:]) +match_count = grep_all_ips(ALL_IPS, cmd) + +print("=========================== SUMMARY ===========================") +for i, count in enumerate(match_count): + if count == -1: + print(f"machine.{i + 1}.log: Connection failed") + else: + print(f"machine.{i + 1}.log: {count} matches") +print(f"Total matches: {max(0, sum(match_count))}") +print("===============================================================") \ No newline at end of file From c061f9ae0af9df220dc000aa010d770723cf0615 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:52:51 -0500 Subject: [PATCH 19/31] Update client.py --- MP1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index 0bd4618..579bf7b 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -71,7 +71,7 @@ def grep_all_ips(ips, cmd): #get all the argument of call import sys -cmd = " ".join(sys.argv[1:]) +cmd = "grep " + " ".join(sys.argv[1:]) match_count = grep_all_ips(ALL_IPS, cmd) print("=========================== SUMMARY ===========================") From 91b78638727414a8ffa4aa5a3244433c8b65547b Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 20:54:41 -0500 Subject: [PATCH 20/31] Update client.py --- MP1/client.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index 579bf7b..20a2906 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import socket +import sys PORT = 5055 ALL_IPS = [ @@ -46,7 +47,6 @@ def grep_all_ips(ips, cmd): try: client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((ip, PORT)) - # print(f"Connected to server at {ip}:{PORT}") full_cmd = cmd + f" ./machine.{i + 1}.log" @@ -68,9 +68,7 @@ def grep_all_ips(ips, cmd): return match_count -#get all the argument of call -import sys - +#main cmd = "grep " + " ".join(sys.argv[1:]) match_count = grep_all_ips(ALL_IPS, cmd) From 47a389ca803f370518cd80d02b965c343eb53ef9 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 22:06:11 -0500 Subject: [PATCH 21/31] testing --- MP1/generate_log.py | 13 +++++++++---- MP1/test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 MP1/test.py diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 2272e9e..9d4271c 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -1,7 +1,7 @@ import random machine_num = input("Enter the machine number: ") -machine_log_file = f"machine.{machine_num}.log" +machine_log_file = f"machine.{machine_num}.test.log" num_lines = int(input("Enter the number of log lines to generate: ")) log_level = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "AUDIT"] @@ -20,7 +20,12 @@ log_messages = [ "System update installed.", ] +#first 11 in this log file should be extact order in log_messages list and then random from there + for i in range(num_lines): - log_entry = f"[{machine_num}-{random.randint(1000, 9999)}] [{log_level[random.randint(0, len(log_level) - 1)]}] {log_messages[random.randint(0, len(log_messages) - 1)]}\n" - with open(machine_log_file, "a") as file: - file.write(log_entry) \ No newline at end of file + if i < 11: + log_entry = f"[{machine_num}-{i}] [{log_level[i % len(log_level)]}] {log_messages[i]}\n" + else: + log_entry = f"[{machine_num}-{i}] [{log_level[random.randint(0, len(log_level) - 1)]}] {log_messages[random.randint(0, len(log_messages) - 1)]}\n" + with open(machine_log_file, "a") as file: + file.write(log_entry) \ No newline at end of file diff --git a/MP1/test.py b/MP1/test.py new file mode 100644 index 0000000..8ce66e4 --- /dev/null +++ b/MP1/test.py @@ -0,0 +1,29 @@ +import pytest +import subprocess + +PORT = 5055 +ALL_IPS = [ + "172.22.156.3", + "172.22.158.2", + "172.22.94.2", + "172.22.156.4", + "172.22.158.3", + "172.22.94.3", + "172.22.156.5", + "172.22.158.4", + "172.22.94.4", + "172.22.156.6" +] + +#generate log files on all the machines before running this test +for i, ip in enumerate(ALL_IPS): + subprocess.run(["ssh", "asing@{ip}", "python3", "generate_log.py", str(i + 1), "100"]) + +#start the server on all the machines before running this test +for i, ip in enumerate(ALL_IPS): + subprocess.run(["ssh", "asing@{ip}", "python3", "server.py"]) + +#ssh into one machine at randome +machine_num = random.randint(1, len(ALL_IPS)) +result = subprocess.run(["ssh", f"asing@{ALL_IPS[machine_num - 1]}", "grep", "ERROR", f"./machine.{machine_num}.test.log"], capture_output=True, text=True) +print(f"Machine {machine_num} grep result:\n{result.stdout}") \ No newline at end of file From bebba25ef4c0f4a85739c1502707942a764e9192 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 22:22:17 -0500 Subject: [PATCH 22/31] init unit testing --- MP1/generate_log.py | 4 ++-- MP1/test.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 9d4271c..626e537 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -1,8 +1,8 @@ import random -machine_num = input("Enter the machine number: ") +machine_num = int(sys.argv[1]) machine_log_file = f"machine.{machine_num}.test.log" -num_lines = int(input("Enter the number of log lines to generate: ")) +num_lines = int(sys.argv[2]) log_level = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "AUDIT"] diff --git a/MP1/test.py b/MP1/test.py index 8ce66e4..ab080d5 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -1,5 +1,5 @@ -import pytest import subprocess +import random PORT = 5055 ALL_IPS = [ @@ -16,14 +16,23 @@ ALL_IPS = [ ] #generate log files on all the machines before running this test +print("Generating log files on all machines...") for i, ip in enumerate(ALL_IPS): - subprocess.run(["ssh", "asing@{ip}", "python3", "generate_log.py", str(i + 1), "100"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) #start the server on all the machines before running this test +print("Starting server on all machines...") for i, ip in enumerate(ALL_IPS): - subprocess.run(["ssh", "asing@{ip}", "python3", "server.py"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 server.py &"]) #ssh into one machine at randome +print("Running grep command on a random machine...") machine_num = random.randint(1, len(ALL_IPS)) -result = subprocess.run(["ssh", f"asing@{ALL_IPS[machine_num - 1]}", "grep", "ERROR", f"./machine.{machine_num}.test.log"], capture_output=True, text=True) -print(f"Machine {machine_num} grep result:\n{result.stdout}") \ No newline at end of file +result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grep 'ERROR' f'./machine.{machine_num}.test.log'"], capture_output=True, text=True) +print(f"Machine {machine_num} grep result:\n{result.stdout}") + +#delete log files on all the machines after running this test +print("Deleting log files on all machines...") +for i, ip in enumerate(ALL_IPS): + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) + \ No newline at end of file From 6da23181f8dee8bb259620c859ba26ad8446afe4 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 22:22:48 -0500 Subject: [PATCH 23/31] Update test.py --- MP1/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/test.py b/MP1/test.py index ab080d5..d20c24e 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -1,5 +1,6 @@ import subprocess import random +import sys PORT = 5055 ALL_IPS = [ @@ -35,4 +36,3 @@ print(f"Machine {machine_num} grep result:\n{result.stdout}") print("Deleting log files on all machines...") for i, ip in enumerate(ALL_IPS): subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) - \ No newline at end of file From 9899fd47417cd230c3f3838d47d5767a120532a3 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 22:23:22 -0500 Subject: [PATCH 24/31] Update generate_log.py --- MP1/generate_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 626e537..9758f0d 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -1,4 +1,5 @@ import random +import sys machine_num = int(sys.argv[1]) machine_log_file = f"machine.{machine_num}.test.log" From 8dfc59f5703e2d6d331db1399afaa35b32de35c4 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 23:29:06 -0500 Subject: [PATCH 25/31] add unit test flag --- MP1/client.py | 12 ++++++++---- MP1/test.py | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index 20a2906..c1a6a3f 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -40,7 +40,7 @@ def receive_message(sock): received_data = receive_exact(sock, message_length) return received_data.decode('utf-8') -def grep_all_ips(ips, cmd): +def grep_all_ips(ips, cmd, if_unit_test): match_count = [] for i, ip in enumerate(ips): @@ -48,7 +48,10 @@ def grep_all_ips(ips, cmd): client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((ip, PORT)) - full_cmd = cmd + f" ./machine.{i + 1}.log" + if if_unit_test: + full_cmd = cmd + f" ./machine.{i + 1}.test.log" + else: + full_cmd = cmd + f" ./machine.{i + 1}.log" send_message(client_socket, full_cmd) data = receive_message(client_socket) @@ -69,8 +72,9 @@ def grep_all_ips(ips, cmd): return match_count #main -cmd = "grep " + " ".join(sys.argv[1:]) -match_count = grep_all_ips(ALL_IPS, cmd) +#if unit test flag exists, then use the test log files instead of the actual log files +cmd = "grep " + " ".join([arg for arg in sys.argv[1:] if arg != "-t"]) +match_count = grep_all_ips(ALL_IPS, cmd, if_unit_test=[x for x in sys.argv].count("-t") > 0) print("=========================== SUMMARY ===========================") for i, count in enumerate(match_count): diff --git a/MP1/test.py b/MP1/test.py index d20c24e..a8874c5 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -19,20 +19,22 @@ ALL_IPS = [ #generate log files on all the machines before running this test print("Generating log files on all machines...") for i, ip in enumerate(ALL_IPS): - subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) #start the server on all the machines before running this test -print("Starting server on all machines...") -for i, ip in enumerate(ALL_IPS): - subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 server.py &"]) +# print("Starting server on all machines...") +# for i, ip in enumerate(ALL_IPS): +# print(f"Starting server on machine {i + 1} ({ip})...") +# subprocess.run([ +# "vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && setsid -f python3 server.py > server.log 2>&1 < /dev/null"]) #ssh into one machine at randome -print("Running grep command on a random machine...") -machine_num = random.randint(1, len(ALL_IPS)) -result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grep 'ERROR' f'./machine.{machine_num}.test.log'"], capture_output=True, text=True) -print(f"Machine {machine_num} grep result:\n{result.stdout}") +# print("Running grep command on a random machine...") +# machine_num = random.randint(1, len(ALL_IPS)) +# result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp 'ERROR' f'./machine.{machine_num}.test.log'"], capture_output=True, text=True) +# print(f"Machine {machine_num} grep result:\n{result.stdout}") #delete log files on all the machines after running this test -print("Deleting log files on all machines...") -for i, ip in enumerate(ALL_IPS): - subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) +# print("Deleting log files on all machines...") +# for i, ip in enumerate(ALL_IPS): +# subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) From d50e1b965de32bbb2fef03430a42a230b8afb650 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 23:34:56 -0500 Subject: [PATCH 26/31] update install cmd --- MP1/scripts/deploy_mp.sh | 2 +- MP1/scripts/install_cmd.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MP1/scripts/deploy_mp.sh b/MP1/scripts/deploy_mp.sh index d28f118..0112a78 100755 --- a/MP1/scripts/deploy_mp.sh +++ b/MP1/scripts/deploy_mp.sh @@ -3,7 +3,7 @@ /Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/kill_mp.sh all for i in {1..10}; do - vpn ssh -n -f -o BatchMode=yes "server$i" "cd fa26_cs425_.group-mp_.team-01/MP1 && git pull origin aryan && /Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/install_cmd.sh" + vpn ssh -n -f -o BatchMode=yes "server$i" "cd fa26_cs425_.group-mp_.team-01/MP1 && git pull origin aryan && ~/fa26_cs425_.group-mp_.team-01/MP1/scripts/install_cmd.sh" done /Users/aryan/Documents/Github/fa26_cs425_.group-mp_.team-01/MP1/scripts/run_mp.sh all \ No newline at end of file diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 9724ff0..609adff 100755 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,6 +1,6 @@ rm -rf "$HOME/bin/grepp" mkdir -p "$HOME/bin" -install -m 755 ../client.py "$HOME/bin/grepp" +install -m 755 ~/fa26_cs425_.group-mp_.team-01/MP1/client.py "$HOME/bin/grepp" echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc" hash -r source "$HOME/.bashrc" \ No newline at end of file From 18ca01ed6bda955c762b9585f29004d1615d0764 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sat, 12 Sep 2026 23:38:36 -0500 Subject: [PATCH 27/31] Update client.py --- MP1/client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index c1a6a3f..1c5f14a 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -79,8 +79,14 @@ match_count = grep_all_ips(ALL_IPS, cmd, if_unit_test=[x for x in sys.argv].coun print("=========================== SUMMARY ===========================") for i, count in enumerate(match_count): if count == -1: - print(f"machine.{i + 1}.log: Connection failed") + if [x for x in sys.argv].count("-t") > 0: + print(f"machine.{i + 1}.test.log: Connection failed") + else: + print(f"machine.{i + 1}.log: Connection failed") else: - print(f"machine.{i + 1}.log: {count} matches") + if [x for x in sys.argv].count("-t") > 0: + print(f"machine.{i + 1}.test.log: {count} matches") + else: + print(f"machine.{i + 1}.log: {count} matches") print(f"Total matches: {max(0, sum(match_count))}") print("===============================================================") \ No newline at end of file From 90931b2d75af5b09ca8cd4594ef29131ee668639 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sun, 13 Sep 2026 00:12:56 -0500 Subject: [PATCH 28/31] Update generate_log.py --- MP1/generate_log.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 9758f0d..512e445 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -21,12 +21,27 @@ log_messages = [ "System update installed.", ] -#first 11 in this log file should be extact order in log_messages list and then random from there +open(machine_log_file, "w").close() for i in range(num_lines): - if i < 11: - log_entry = f"[{machine_num}-{i}] [{log_level[i % len(log_level)]}] {log_messages[i]}\n" - else: - log_entry = f"[{machine_num}-{i}] [{log_level[random.randint(0, len(log_level) - 1)]}] {log_messages[random.randint(0, len(log_messages) - 1)]}\n" - with open(machine_log_file, "a") as file: - file.write(log_entry) \ No newline at end of file + #on all + if i == 0: + log_entry = f"[{machine_num}-{i}] [INFO] TEST_ALL\n" + #unique + elif i == 1: + log_entry = f"[{machine_num}-{i}] [DEBUG] TEST_UNIQUE\n" + #on some + elif i == 2 and machine_num in [1, 3, 5, 7, 9]: + log_entry = f"[{machine_num}-{i}] [ERROR] TEST_SOME\n" + + elif 3 <= i < 13: + log_entry = f"[{machine_num}-{i}] [INFO] TEST_MEDIUM\n" + + else: + log_entry = f"[{machine_num}-{i}] [{random.choice(log_level)}] {random.choice(log_messages)}\n" + + with open(machine_log_file, "a") as f: + f.write(log_entry) + + + \ No newline at end of file From 8d508d26a681ec02ddcc20f4e8c8c117330b6789 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sun, 13 Sep 2026 00:23:03 -0500 Subject: [PATCH 29/31] testing --- MP1/generate_log.py | 4 ++-- MP1/test.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 512e445..db0571e 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -27,8 +27,8 @@ for i in range(num_lines): #on all if i == 0: log_entry = f"[{machine_num}-{i}] [INFO] TEST_ALL\n" - #unique - elif i == 1: + #unique + elif i == 1 and machine_num == [2, 4, 6, 8, 10]: log_entry = f"[{machine_num}-{i}] [DEBUG] TEST_UNIQUE\n" #on some elif i == 2 and machine_num in [1, 3, 5, 7, 9]: diff --git a/MP1/test.py b/MP1/test.py index a8874c5..d8d440a 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -35,6 +35,6 @@ for i, ip in enumerate(ALL_IPS): # print(f"Machine {machine_num} grep result:\n{result.stdout}") #delete log files on all the machines after running this test -# print("Deleting log files on all machines...") -# for i, ip in enumerate(ALL_IPS): -# subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) +print("Deleting log files on all machines...") +for i, ip in enumerate(ALL_IPS): + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) From e9f858ab7c0bbc97cc2ad5a4ba2c3839d9db2297 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sun, 13 Sep 2026 00:32:49 -0500 Subject: [PATCH 30/31] minor fix --- MP1/generate_log.py | 2 +- MP1/test.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MP1/generate_log.py b/MP1/generate_log.py index db0571e..787962e 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -28,7 +28,7 @@ for i in range(num_lines): if i == 0: log_entry = f"[{machine_num}-{i}] [INFO] TEST_ALL\n" #unique - elif i == 1 and machine_num == [2, 4, 6, 8, 10]: + elif i == 1 and machine_num in [2, 4, 6, 8, 10]: log_entry = f"[{machine_num}-{i}] [DEBUG] TEST_UNIQUE\n" #on some elif i == 2 and machine_num in [1, 3, 5, 7, 9]: diff --git a/MP1/test.py b/MP1/test.py index d8d440a..a8874c5 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -35,6 +35,6 @@ for i, ip in enumerate(ALL_IPS): # print(f"Machine {machine_num} grep result:\n{result.stdout}") #delete log files on all the machines after running this test -print("Deleting log files on all machines...") -for i, ip in enumerate(ALL_IPS): - subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) +# print("Deleting log files on all machines...") +# for i, ip in enumerate(ALL_IPS): +# subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) From cff433eb8dc8970a5be869c957de7f465431f406 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Sun, 13 Sep 2026 01:09:02 -0500 Subject: [PATCH 31/31] Update test.py --- MP1/test.py | 299 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 287 insertions(+), 12 deletions(-) diff --git a/MP1/test.py b/MP1/test.py index a8874c5..0501932 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -16,25 +16,300 @@ ALL_IPS = [ "172.22.156.6" ] +tests = ["TEST_ALL", "TEST_UNIQUE", "TEST_SOME", "TEST_MEDIUM"] +results = ["""Filename: machine.1.log +Matches: 1 +1:[1-0] [INFO] TEST_ALL + +Filename: machine.2.log +Matches: 1 +1:[2-0] [INFO] TEST_ALL + +Filename: machine.3.log +Matches: 1 +1:[3-0] [INFO] TEST_ALL + +Filename: machine.4.log +Matches: 1 +1:[4-0] [INFO] TEST_ALL + +Filename: machine.5.log +Matches: 1 +1:[5-0] [INFO] TEST_ALL + +Filename: machine.6.log +Matches: 1 +1:[6-0] [INFO] TEST_ALL + +Filename: machine.7.log +Matches: 1 +1:[7-0] [INFO] TEST_ALL + +Filename: machine.8.log +Matches: 1 +1:[8-0] [INFO] TEST_ALL + +Filename: machine.9.log +Matches: 1 +1:[9-0] [INFO] TEST_ALL + +Filename: machine.10.log +Matches: 1 +1:[10-0] [INFO] TEST_ALL + +=========================== SUMMARY =========================== +machine.1.test.log: 1 matches +machine.2.test.log: 1 matches +machine.3.test.log: 1 matches +machine.4.test.log: 1 matches +machine.5.test.log: 1 matches +machine.6.test.log: 1 matches +machine.7.test.log: 1 matches +machine.8.test.log: 1 matches +machine.9.test.log: 1 matches +machine.10.test.log: 1 matches +Total matches: 10 +===============================================================""", +""" +Filename: machine.2.log +Matches: 1 +2:[2-1] [DEBUG] TEST_UNIQUE + +Filename: machine.4.log +Matches: 1 +2:[4-1] [DEBUG] TEST_UNIQUE + +Filename: machine.6.log +Matches: 1 +2:[6-1] [DEBUG] TEST_UNIQUE + +Filename: machine.8.log +Matches: 1 +2:[8-1] [DEBUG] TEST_UNIQUE + +Filename: machine.10.log +Matches: 1 +2:[10-1] [DEBUG] TEST_UNIQUE + +=========================== SUMMARY =========================== +machine.1.test.log: 0 matches +machine.2.test.log: 1 matches +machine.3.test.log: 0 matches +machine.4.test.log: 1 matches +machine.5.test.log: 0 matches +machine.6.test.log: 1 matches +machine.7.test.log: 0 matches +machine.8.test.log: 1 matches +machine.9.test.log: 0 matches +machine.10.test.log: 1 matches +Total matches: 5 +=============================================================== +""", +""" +Filename: machine.1.log +Matches: 1 +3:[1-2] [ERROR] TEST_SOME + +Filename: machine.3.log +Matches: 1 +3:[3-2] [ERROR] TEST_SOME + +Filename: machine.5.log +Matches: 1 +3:[5-2] [ERROR] TEST_SOME + +Filename: machine.7.log +Matches: 1 +3:[7-2] [ERROR] TEST_SOME + +Filename: machine.9.log +Matches: 1 +3:[9-2] [ERROR] TEST_SOME + +=========================== SUMMARY =========================== +machine.1.test.log: 1 matches +machine.2.test.log: 0 matches +machine.3.test.log: 1 matches +machine.4.test.log: 0 matches +machine.5.test.log: 1 matches +machine.6.test.log: 0 matches +machine.7.test.log: 1 matches +machine.8.test.log: 0 matches +machine.9.test.log: 1 matches +machine.10.test.log: 0 matches +Total matches: 5 +=============================================================== +""", +""" +Filename: machine.1.log +Matches: 10 +4:[1-3] [INFO] TEST_MEDIUM +5:[1-4] [INFO] TEST_MEDIUM +6:[1-5] [INFO] TEST_MEDIUM +7:[1-6] [INFO] TEST_MEDIUM +8:[1-7] [INFO] TEST_MEDIUM +9:[1-8] [INFO] TEST_MEDIUM +10:[1-9] [INFO] TEST_MEDIUM +11:[1-10] [INFO] TEST_MEDIUM +12:[1-11] [INFO] TEST_MEDIUM +13:[1-12] [INFO] TEST_MEDIUM + +Filename: machine.2.log +Matches: 10 +4:[2-3] [INFO] TEST_MEDIUM +5:[2-4] [INFO] TEST_MEDIUM +6:[2-5] [INFO] TEST_MEDIUM +7:[2-6] [INFO] TEST_MEDIUM +8:[2-7] [INFO] TEST_MEDIUM +9:[2-8] [INFO] TEST_MEDIUM +10:[2-9] [INFO] TEST_MEDIUM +11:[2-10] [INFO] TEST_MEDIUM +12:[2-11] [INFO] TEST_MEDIUM +13:[2-12] [INFO] TEST_MEDIUM + +Filename: machine.3.log +Matches: 10 +4:[3-3] [INFO] TEST_MEDIUM +5:[3-4] [INFO] TEST_MEDIUM +6:[3-5] [INFO] TEST_MEDIUM +7:[3-6] [INFO] TEST_MEDIUM +8:[3-7] [INFO] TEST_MEDIUM +9:[3-8] [INFO] TEST_MEDIUM +10:[3-9] [INFO] TEST_MEDIUM +11:[3-10] [INFO] TEST_MEDIUM +12:[3-11] [INFO] TEST_MEDIUM +13:[3-12] [INFO] TEST_MEDIUM + +Filename: machine.4.log +Matches: 10 +4:[4-3] [INFO] TEST_MEDIUM +5:[4-4] [INFO] TEST_MEDIUM +6:[4-5] [INFO] TEST_MEDIUM +7:[4-6] [INFO] TEST_MEDIUM +8:[4-7] [INFO] TEST_MEDIUM +9:[4-8] [INFO] TEST_MEDIUM +10:[4-9] [INFO] TEST_MEDIUM +11:[4-10] [INFO] TEST_MEDIUM +12:[4-11] [INFO] TEST_MEDIUM +13:[4-12] [INFO] TEST_MEDIUM + +Filename: machine.5.log +Matches: 10 +4:[5-3] [INFO] TEST_MEDIUM +5:[5-4] [INFO] TEST_MEDIUM +6:[5-5] [INFO] TEST_MEDIUM +7:[5-6] [INFO] TEST_MEDIUM +8:[5-7] [INFO] TEST_MEDIUM +9:[5-8] [INFO] TEST_MEDIUM +10:[5-9] [INFO] TEST_MEDIUM +11:[5-10] [INFO] TEST_MEDIUM +12:[5-11] [INFO] TEST_MEDIUM +13:[5-12] [INFO] TEST_MEDIUM + +Filename: machine.6.log +Matches: 10 +4:[6-3] [INFO] TEST_MEDIUM +5:[6-4] [INFO] TEST_MEDIUM +6:[6-5] [INFO] TEST_MEDIUM +7:[6-6] [INFO] TEST_MEDIUM +8:[6-7] [INFO] TEST_MEDIUM +9:[6-8] [INFO] TEST_MEDIUM +10:[6-9] [INFO] TEST_MEDIUM +11:[6-10] [INFO] TEST_MEDIUM +12:[6-11] [INFO] TEST_MEDIUM +13:[6-12] [INFO] TEST_MEDIUM + +Filename: machine.7.log +Matches: 10 +4:[7-3] [INFO] TEST_MEDIUM +5:[7-4] [INFO] TEST_MEDIUM +6:[7-5] [INFO] TEST_MEDIUM +7:[7-6] [INFO] TEST_MEDIUM +8:[7-7] [INFO] TEST_MEDIUM +9:[7-8] [INFO] TEST_MEDIUM +10:[7-9] [INFO] TEST_MEDIUM +11:[7-10] [INFO] TEST_MEDIUM +12:[7-11] [INFO] TEST_MEDIUM +13:[7-12] [INFO] TEST_MEDIUM + +Filename: machine.8.log +Matches: 10 +4:[8-3] [INFO] TEST_MEDIUM +5:[8-4] [INFO] TEST_MEDIUM +6:[8-5] [INFO] TEST_MEDIUM +7:[8-6] [INFO] TEST_MEDIUM +8:[8-7] [INFO] TEST_MEDIUM +9:[8-8] [INFO] TEST_MEDIUM +10:[8-9] [INFO] TEST_MEDIUM +11:[8-10] [INFO] TEST_MEDIUM +12:[8-11] [INFO] TEST_MEDIUM +13:[8-12] [INFO] TEST_MEDIUM + +Filename: machine.9.log +Matches: 10 +4:[9-3] [INFO] TEST_MEDIUM +5:[9-4] [INFO] TEST_MEDIUM +6:[9-5] [INFO] TEST_MEDIUM +7:[9-6] [INFO] TEST_MEDIUM +8:[9-7] [INFO] TEST_MEDIUM +9:[9-8] [INFO] TEST_MEDIUM +10:[9-9] [INFO] TEST_MEDIUM +11:[9-10] [INFO] TEST_MEDIUM +12:[9-11] [INFO] TEST_MEDIUM +13:[9-12] [INFO] TEST_MEDIUM + +Filename: machine.10.log +Matches: 10 +4:[10-3] [INFO] TEST_MEDIUM +5:[10-4] [INFO] TEST_MEDIUM +6:[10-5] [INFO] TEST_MEDIUM +7:[10-6] [INFO] TEST_MEDIUM +8:[10-7] [INFO] TEST_MEDIUM +9:[10-8] [INFO] TEST_MEDIUM +10:[10-9] [INFO] TEST_MEDIUM +11:[10-10] [INFO] TEST_MEDIUM +12:[10-11] [INFO] TEST_MEDIUM +13:[10-12] [INFO] TEST_MEDIUM + +=========================== SUMMARY =========================== +machine.1.test.log: 10 matches +machine.2.test.log: 10 matches +machine.3.test.log: 10 matches +machine.4.test.log: 10 matches +machine.5.test.log: 10 matches +machine.6.test.log: 10 matches +machine.7.test.log: 10 matches +machine.8.test.log: 10 matches +machine.9.test.log: 10 matches +machine.10.test.log: 10 matches +Total matches: 100 +=============================================================== +"""] + + #generate log files on all the machines before running this test print("Generating log files on all machines...") for i, ip in enumerate(ALL_IPS): subprocess.run(["vpn", "ssh", f"asing271@{ip}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) #start the server on all the machines before running this test -# print("Starting server on all machines...") -# for i, ip in enumerate(ALL_IPS): -# print(f"Starting server on machine {i + 1} ({ip})...") -# subprocess.run([ -# "vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && setsid -f python3 server.py > server.log 2>&1 < /dev/null"]) +print("Starting server on all machines...") +for i, ip in enumerate(ALL_IPS): + print(f"Starting server on machine {i + 1} ({ip})...") + subprocess.run([ + "vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && setsid -f python3 server.py > server.log 2>&1 < /dev/null"]) #ssh into one machine at randome -# print("Running grep command on a random machine...") -# machine_num = random.randint(1, len(ALL_IPS)) -# result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp 'ERROR' f'./machine.{machine_num}.test.log'"], capture_output=True, text=True) -# print(f"Machine {machine_num} grep result:\n{result.stdout}") +machine_num = random.randint(1, len(ALL_IPS)) +print(f"Running grep command on a {machine_num} random machine...") +for i in tests: + result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp {i} -t"], capture_output=True, text=True) + if result.stdout.strip() == results[tests.index(i)].strip(): + print("PASS {i} test") + else: + print("FAIL {i} test") #delete log files on all the machines after running this test -# print("Deleting log files on all machines...") -# for i, ip in enumerate(ALL_IPS): -# subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) +print("Deleting log files on all machines...") +for i, ip in enumerate(ALL_IPS): + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"])