import paramiko
def remote_cat_logs(host, port, username, password, log_files, output_file):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
with open(output_file, 'w') as f:
for log_file in log_files:
stdin, stdout, stderr = ssh.exec_command(f"cat {log_file}")
for line in stdout:
f.write(line)
ssh.close()
if __name__ == "__main__":
host = "远程服务器IP"
port = 22
username = "用户名"
password = "密码"
log_files = ["/path/to/log1", "/path/to/log2"]
output_file = "/path/to/output.log"
remote_cat_logs(host, port, username, password, log_files, output_file)
11-04
9390
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)