import paramiko
#读取服务器日志,并打印
def get_server_log():
hostname = “172.16.176.xx”
port = 22
username = “app”
password = “123456”
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port, username, password, compress=True)
remote_command = “tail -n100 /home/app/sxpservice/logs/server.log”
stdin, stdout, stderr = client.exec_command(remote_command)
last_line = stdout.read()
a = last_line.decode(‘utf-8’)
print(a)