From 4ccec278bf27b4f06087495feebcc430634edf7c Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:27:55 -0500 Subject: [PATCH] custom command check --- MP1/client.py | 9 +++++---- MP1/scripts/grepp.py | 33 --------------------------------- MP1/scripts/install_cmd.sh | 4 ++-- 3 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 MP1/scripts/grepp.py diff --git a/MP1/client.py b/MP1/client.py index b75106b..c37f832 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -1,4 +1,4 @@ -# client.py +#!/usr/bin/env python3 import socket PORT = 5055 @@ -15,14 +15,14 @@ ALL_IPS = [ "172.22.156.6" ] -def grep_all_ips(ips): +def grep_all_ips(ips, cmd): for ip in ips: try: client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((ip, PORT)) print(f"Connected to server at {ip}:{PORT}") - client_socket.sendall("ls -la".encode()) + client_socket.sendall(cmd.encode()) data = client_socket.recv(65536) print("Received:", data.decode()) except Exception as e: @@ -30,4 +30,5 @@ def grep_all_ips(ips): finally: client_socket.close() -grep_all_ips(ALL_IPS) \ No newline at end of file +cmd = input("Enter the command to execute on all servers: ") +grep_all_ips(ALL_IPS, cmd) \ No newline at end of file diff --git a/MP1/scripts/grepp.py b/MP1/scripts/grepp.py deleted file mode 100644 index 01656c2..0000000 --- a/MP1/scripts/grepp.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python3 -import socket - -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" -] - -def grep_all_ips(ips): - for ip in ips: - try: - client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - client_socket.connect((ip, PORT)) - print(f"Connected to server at {ip}:{PORT}") - - client_socket.sendall("ls -la".encode()) - data = client_socket.recv(65536) - print("Received:", data.decode()) - except Exception as e: - print(f"Failed to connect to {ip}:{PORT} - {e}") - finally: - client_socket.close() - -grep_all_ips(ALL_IPS) \ No newline at end of file diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 49a8307..34a5f30 100644 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,6 +1,6 @@ -chmod +x grepp.py +chmod +x ../client.py mkdir -p ~/bin -cp grepp.py ~/bin/grepp +cp ../client.py ~/bin/grepp chmod +x ~/bin/grepp export PATH="$HOME/bin:$PATH" > ~/.bashrc source ~/.bashrc \ No newline at end of file