#!/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()

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐