Python sftp到远程服务器读取日志文件
2016-06-25 14:06
696 查看
#!/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()
#!/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()
相关文章推荐
- python-numpy、scipy
- python使用pytesseract识别验证码的方法
- python 安装easy_install和pip
- Python学习-baseNo.1
- python根据文件目录、文件类型和文件与当前时间差删除文件
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xc4 in position 0: i报错问题
- Python案例-开发之路-计算器
- python加密解密
- vim环境设置(应用于python编程)
- Python 包管理工具解惑
- python面向对象基础
- Python快速入门学习笔记(一)
- python cookielib
- Python机器学习实战笔记之KNN算法
- 地铁译:Spark for python developers ---Spark处理后的数据可视化
- 浅谈Python中的yield表达式
- python安装mysql-python简明笔记(ubuntu环境)
- python urllib访问网站
- python中的with-as语句学习
- 【Python学习日记】函数式编程 之 高阶函数