_, stdout, stderr = self.ssh.exec_command(cmd, get_pty=True)
while True:
v = stdout.channel.recv(1024)
if not v:
break
print(str(v))
time.sleep(3)
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname, port, username, password=password)
sftp = ssh.open_sftp()
command = 'cd opt' \
'find /opt -type f -exec ls -p {} + | tee files.txt | wc -l'
stdin, stdout, stderr = ssh.exec_command(command)
lines = stdout.readlines()
print(lines)
output = stdout.read().decode('utf-8')
print('output', output)
_, stdout, stderr = ssh.exec_command(command, get_pty=True)
while True:
v = stdout.channel.recv(1024)
if not v:
break
print(str(v))
time.sleep(3)
sftp.close()
ssh.close()
参考
https://www.cnblogs.com/landhu/p/15222967.html