-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyupload.py
62 lines (56 loc) · 1.58 KB
/
kyupload.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#coding=utf-8
import paramiko,os,time
from kypform import settings
import random
import base64
def ordianry_ssh(host,username,password,port,cmd):
password = de_str(settings.SECRET_KEY,str(password))
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname = host,port=int(port),username=username,password=password)
stdin, stdout, stderr = s.exec_commane(cmd)
result = stdout.read()
result = str(result)
s.close()
return result
def verification_ssh(host,username,password,port,root_pwd,cmd):
root_pwd = de_str(str(settings.SECRET_KEY),str(root_pwd))
password = de_str(str(settings.SECRET_KEY),str(password))
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname = host,username = username,port=int(port),password = password)
if username != "root":
ssh = s.invoke_shell()
time.sleep(0.1)
ssh.send('su -\n')
buff = ''
while not buff.endswith(': ') or buff.endswith(': ')
resp = ssh.recv(9999)
buff += resp
ssh.send(root_pwd)
ssh.send('\n')
buff = ''
while not buff.endswith('# '):
resp = ssh.recv(9999)
buff += resp
ssh.send(cmd)
ssh.send('\n')
buff = ''
while not buff.endswith('# '):
resp = ssh.recv(9999)
buff += resp
s.close()
result = buff
else:
stdin, stdout, stderr = s.exec_command(cmd)
result = stdout.read()
result = str(result)
s.close()
return result
def upload_run_script(tasklogpath,host,script_list):
try:
out = open(tasklogpath,'a')
script_dir = str(host.script_dir)
cmd