commit 5842f0748f2af439776bcf466afc6cf0d04d8c5b Author: Mark Date: Thu Aug 29 15:25:01 2024 +0200 Add main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ef32375 --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +from fabric import Connection + +hosts = ["192.168.145.100", "192.168.145.101"] +username = "" +password = "" + +# Loop through the hosts and run the command +for host in hosts: + # Create a connection object + conn = Connection(host=host, user=username, connect_kwargs={"password": password}) + + # Command to add user and set password using sudo + command1 = """sudo -S bash -c 'adduser --gecos "" --disabled-password alex && echo "user:pass" | sudo chpasswd'""" + result1 = conn.run(f"echo {password} | {command1}", pty=True) + print(f"Output from {host}:\n{result1.stdout.strip()}") + + command2 = "sudo -S adduser user sudo" + result2 = conn.run(f"echo {password} | {command2}", pty=True) + print(f"Output from {host}:\n{result2.stdout.strip()}") + + # Close the connection + conn.close()