[Python] Python sftp到远程服务器读取日志文件
#!/usr/bin/python# -*- coding:utf-8 -*-import paramikoremotedir = "/root"remotefile = "/root/log_history.txt"hostname = "10.142.152.xxx"port = 22username = "user&quo
·
#!/usr/bin/python
# -*- coding:utf-8 -*-
import paramiko
remotedir = "/root"
remotefile = "/root/log_history.txt"
hostname = "10.142.152.xxx"
port = 22
username = "user"
password = "******"
paramiko.util.log_to_file('paramiko.log')
s = paramiko.SSHClient()
s.load_system_host_keys()
s.connect(hostname,port,username,password)
command = 'tail -30 /root/log_history.txt'
#command = 'df -h'
stdin,stdout,stderr = s.exec_command(command)
#print(2,stdout.read())
logs = stdout.readlines()
for i in range(len(logs)):
print(logs[i].rstrip())
s.close()
更多推荐
已为社区贡献1条内容
所有评论(0)