-
Notifications
You must be signed in to change notification settings - Fork 11
/
rcmd.py
executable file
·42 lines (32 loc) · 887 Bytes
/
rcmd.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
36
37
38
39
40
41
42
# remote execute bash command
#! /bin/python
import init
import paramiko
import time
import sys
ips = init.ips
username = init.username
password = init.newpassword
def usage():
print "Usage python %s command" % sys.argv[0]
def execcmd(cmd):
for ip in ips:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip,22,username,password,timeout=5)
print "################################ %15s ################################## " % ip
stdin, stdout, stderr = ssh.exec_command(cmd)
print cmd
print stdout.read().strip()
ssh.close()
except:
print ip, cmd
def main():
if len(sys.argv) != 2:
usage()
exit()
cmd = sys.argv[1]
execcmd(cmd)
if __name__ == '__main__':
main()