-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel-ssh-tauros.py
executable file
·35 lines (32 loc) · 1.02 KB
/
parallel-ssh-tauros.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import sys, getopt, socket
from pssh import ParallelSSHClient
def main(argv):
hosts = []
cmd = ''
try:
opts, args = getopt.getopt(argv,"ht:c:",["targets=","cmd="])
except getopt.GetoptError:
print 'parallel-ssh-tauros.py -t <ipsfile> -c <cmd>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'parallel-ssh-tauros.py -t <ipsfile> -c <cmd>'
sys.exit()
elif opt in ("-t", "--targets"):
filename = arg
with open(filename, "r") as ips:
for ip in ips:
hosts.append(ip.strip())
elif opt in ("-c", "--cmd"):
cmd = arg
print '==== Targets detected: ', len(hosts)
print '==== Cmd: ', cmd
password = open("password").readline().strip()
client = ParallelSSHClient(hosts, user='root', password=password)
output = client.run_command(cmd)
for host in output:
for line in output[host]['stdout']:
print("=> Host %s - output: %s" % (host, line))
if __name__ == "__main__":
main(sys.argv[1:])