#!usr/bin/python
# coding: utf-8
import paramiko
import json
remotedir='/tmp/log'
remotefile = 'bst_manager-2019-04-17-info.log'
hostname = '192.168.50.34'
port = 8022
username = 'root'
password ='*****'
command = """tail -n 30 /tmp/log/bst_manager-2019-04-17-info.log | grep 'other'"""
def ssh_remote():
""" 1、基于用户名和密码连接
"""
print ("基于用户名和密码连接")
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不再know_host文件的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname, port, username, password)
# 执行命令
stdin, stdout, stderr = ssh.exec_command(command)
data = stdout.readline()
cl