Skip to content

Instantly share code, notes, and snippets.

@eekwong
Last active May 13, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eekwong/5baa754a863602d109effbaf0476885a to your computer and use it in GitHub Desktop.
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.
#!/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