-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_execute.py
More file actions
43 lines (37 loc) · 1.21 KB
/
Copy pathssh_execute.py
File metadata and controls
43 lines (37 loc) · 1.21 KB
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
43
from time import sleep
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ip = ['x.x.x.35','x.x.x.36']
def vmrun():
while True:
stdout, stderr = ssh.exec_command('/usr/bin/vmrun list')
output = stdout.readlines()
output = stderr.readlines()
print ''.join(output)
sleep(3)
def execmd_with_param(ip):
print (ip)
commands = [
"mv /home/root/witopia/{}.conf /home/offshore/witopia/config.conf".format(ip)
]
for cmd in commands:
stdin, stdout, stderr = ssh.exec_command(cmd)
output = None
if stdout:
output = stdout.readlines()
if stderr:
output = stderr.readlines()
print ''.join(output)
ssh.close()
if __name__ == "__main__":
for ips in ip:
try:
if "10.14.47.1" in ips:
ssh.connect(ips,port=22,username='root',password='test',look_for_keys=False,timeout=11)
else:
ssh.connect(ips, port=22, username='root', password='test', look_for_keys=False, timeout=11)
# execmd_with_param(ips)
# vmrun()
except Exception as e:
print e