python-(subprocess, commands)
class Exe_local_command():def __init__(self, command):‘‘‘ :param command: ‘‘‘ self.command = commanddef exe_command(self):‘‘‘ :return: ‘‘‘ exitstatus, exitresult = commands.getstatusoutput(self.command)return exitstatus, exitresultdef find_shell(self):‘‘‘ @summary:find: find_command = ‘find /tmp/atp1 -name "*.log.*"‘ :return: ‘‘‘ find_status, find_result = self.exe_command()if find_status == 0 and len(find_result) > 0 and find_result.find("No such file or directory") == -1:return find_resultclass Exe_remote_command():def __init__(self, command, ip, port, user, password):‘‘‘ :param command: ‘‘‘ self.command = commandself.ip = ipself.port = portself.user = userself.password = passworddef exe_command(self):‘‘‘ :return: ‘‘‘ completed_command = (‘ssh -o StrictHostKeychecking=no -p {0} {1}@{2} "{3}"‘.format(self.port, self.user, self.ip, self.command))if self.password != None: completed_command = "sshpass -p {0} {1}".format(self.password, completed_command) sub_process = subprocess.Popen(completed_command, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True) outtext = ‘‘ #实时获取命令执行的信息 while sub_process.poll() is None: line = sub_process.stdout.readline() outtext += lineline = line.strip()exitstatus = sub_process.returncode
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16