Last active
May 13, 2020 19:11
-
-
Save eekwong/5baa754a863602d109effbaf0476885a to your computer and use it in GitHub Desktop.
multissh is a script that runs a command in multiple hosts using the same password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import getpass | |
import paramiko | |
import socket | |
def main(): | |
password = getpass.getpass() | |
hosts = raw_input("Hosts: ").split(",") | |
command = raw_input("Command: ").strip() | |
for host in hosts: | |
host = host.strip() | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
try: | |
ssh.connect(host, 22, getpass.getuser(), password) | |
_, stdout, stderr = ssh.exec_command(command) | |
print("{} : {}".format(host, "".join(stdout.readlines()).strip())) | |
except paramiko.ssh_exception.AuthenticationException: | |
print("{} : failed in authentication".format(host)) | |
except socket.gaierror as e: | |
print(e) | |
print() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment