注意不能执行top等动态命令
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'babyshen' __version__ = '1.0.0' import paramiko class SSh(object): def __init__(self,port,username,password): self.port = port self.username = username self.password = password def ssh_con(self,host,ip,cmd): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,self.port,self.username,self.password) stdin, stdout, stderr = ssh.exec_command(cmd) res,err = stdout.read(),stderr.read() result = res if res else err print('